[英]Python + Mechanize Async Tasks
因此,我有這段Python代碼可以通過一個漂亮的頁面運行,並從中刮取一些鏈接。 提取方法包含一些魔術,可以提取所需的內容。 但是,運行頁面一次又一次地獲取很慢-有沒有辦法在python中做到這一點異步,以便我可以啟動多個get請求並並行處理頁面?
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
Beautiful Soup很慢,如果您想獲得更好的性能,請改用lxml,或者如果您有很多CPU,也許可以嘗試對隊列使用多處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.