Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我想从网站自动抓取1到10页的数据。我怎么做?_Python_Python 2.7_Web Scraping_Web Crawler_Ipython - Fatal编程技术网

Python 我想从网站自动抓取1到10页的数据。我怎么做?

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

从上述代码中,我从第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_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