我正在尝试从 nydaily 新闻和其他网站获取 htmltext,但我无法让 mechanize 正确超时。当超时为 0.01 时,它会立即超时,但是当超时更合理(1.0)时,它会运行约 2 分钟,然后给我这个错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run
already_pickled=True)
File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet
sock.send(struct.pack("l", len(sent_data)) + sent_data)
error: [Errno 32] Broken pipe
import mechanize
br = mechanize.Browser()
url = 'http://www.nydailynews.com/services/feeds'
htmltext= br.open(url,timeout=1.0).read()
print htmltext[:200]