【发布时间】:2017-05-03 10:34:19
【问题描述】:
我正在尝试制作一个 Python 网络爬虫,但由于某种原因,当我尝试爬取亚马逊之类的网站时,我的程序打印出来的唯一内容是“无”
import requests
from bs4 import BeautifulSoup
def spider(max_pages):
page = 1
while page <= max_pages:
url = 'https://www.amazon.com/s/ref=sr_pg_2?rh=i%3Aaps%2Ck%3Apython&page=' + str(page) + '&keywords=python&ie=UTF8&qid=1482022018&spIA=B01M63XMN1,B00WFP9S2E'
source = requests.get(url)
plain_text = source.text
obj = BeautifulSoup(plain_text, "html5lib")
for link in obj.find_all('a'):
href = link.get(url)
print(href)
page += 1
spider(1)
【问题讨论】:
-
您是否尝试过另一个更简单的页面?一些网站不允许网络爬虫
-
我可以尝试什么页面?
-
试试thenewboston.com。如果您有兴趣,该网站的创建者也有一个非常深入的 python 爬虫教程。 Here's YouTube 播放列表
标签: python request beautifulsoup