【发布时间】:2012-10-01 11:56:03
【问题描述】:
我有以下代码:
#!/usr/bin/env python
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
mech = Browser()
mech.set_handle_robots(False)
url = "http://storage.googleapis.com/patents/retro/2011/ad20111231-02.zip"
page = mech.open(url)
html = page.read()
soup = BeautifulSoup(html)
print soup.prettify()
非常简单的网络爬虫尝试从网页下载 .zip 文件。当我运行这段代码并记住这个文件是 4kb 时,程序只是没有完成,就好像它处于无限的 while 循环中一样。我在这里做了什么?
【问题讨论】:
-
您等了多长时间?我刚刚尝试使用
timeit(python -m timeit -n 1 -r 1 -s "import requests" "r = requests.get('http://storage.googleapis.com/patents/retro/2011/ad20111231-02.zip').content") 花了 113 秒。你至少等了那么久吗?
标签: python beautifulsoup mechanize