Python 我想从网站自动抓取1到10页的数据。我怎么做?
从上述代码中,我从第2页删除了(评论/投诉)。Python 我想从网站自动抓取1到10页的数据。我怎么做?,python,python-2.7,web-scraping,web-crawler,ipython,Python,Python 2.7,Web Scraping,Web Crawler,Ipython,从上述代码中,我从第2页删除了(评论/投诉)。 如何在所有页面中自动读取数据()为什么不将函数环绕在一个范围内的for循环中 import requests from bs4 import BeautifulSoup My_Url = "http://questions.consumercomplaints.in/page/2" Data = requests.get(My_Url) Soup = BeautifulSoup(Data.content) head_id = Soup.find_a
如何在所有页面中自动读取数据()为什么不将函数环绕在一个范围内的for循环中
import requests
from bs4 import BeautifulSoup
My_Url = "http://questions.consumercomplaints.in/page/2"
Data = requests.get(My_Url)
Soup = BeautifulSoup(Data.content)
head_id = Soup.find_all({"div":"href"})
len(head_id)
for i in head_id:
print i.text
让我们看看range函数是如何工作的。我遇到了一个错误“无法连接'str'和'int'对象”,这是将i类型转换为字符串所需的。我已经更新了答案。我可以投票给asnwer,由声誉低于15的人投票:(
import requests
from bs4 import BeautifulSoup
for i in range(3,11):
My_Url = "http://questions.consumercomplaints.in/page/" + str(i)
Data = requests.get(My_Url)
Soup = BeautifulSoup(Data.content)
head_id = Soup.find_all({"div":"href"})
len(head_id)
for i in head_id:
print i.text