【发布时间】:2010-12-19 00:41:55
【问题描述】:
所以我有一段 Python 代码,它在一个美味的页面中运行,并从中删除了一些链接。 extract 方法包含一些提取所需内容的魔法。但是,一个接一个地运行页面获取速度非常慢 - 有没有办法在 python 中异步执行此操作,以便我可以启动多个获取请求并并行处理页面?
url= "http://www.delicious.com/search?p=varun"
page = br.open(url)
html = page.read()
soup = BeautifulSoup(html)
extract(soup)
count=1
#Follows regexp match onto consecutive pages
while soup.find ('a', attrs={'class': 'pn next'}):
print "yay"
print count
endOfPage = "false"
try :
page3 = br.follow_link(text_regex="Next")
html3 = page3.read()
soup3 = BeautifulSoup(html3)
extract(soup3)
except:
print "End of Pages"
endOfPage = "true"
if valval == "true":
break
count = count +1
【问题讨论】:
-
查看
threading和multiprocessing。 -
是否有任何特定的框架可以很好地与 mechanize 和 BeautifulSoup 配合使用?
标签: python multithreading web-crawler mechanize scrape