我正在尝试创建一个爬虫,它可以抓取网站上的前100个页面:
我的代码是这样的:
def extractproducts(pagenumber):
contenturl = "http://websiteurl/page/" + str(pagenumber)
content = BeautifulSoup(urllib2.urlopen(contenturl).read())
print pagehtml
pagenumberlist = range(1, 101)
for pagenumber in pagenumberlist:
extractproducts(pagenumber)
在这种情况下,如何使用线程模块,以便urllib使用多线程一次抓取X个url?在
/新手出局
很有可能,您希望使用multiprocessing。有一个
Pool
可以用来并行执行多个任务:如果函数返回任何值,
^{pr2}$Pool.map
将返回返回值列表:相关问题 更多 >
编程相关推荐