gpt4 book ai didi

python mechanize 不会超时并卡在打开 url 中

转载 作者:行者123 更新时间:2023-11-28 22:52:33 26 4
gpt4 key购买 nike

我正在尝试打开一个 url 列表,我设置了一个超时值以排除未打开的 url。但是,当我遇到以下网址时,它会卡住并且不会超时。网站在浏览器中打开正常,请问问题出在哪里?

url='http://www.gizmodo.it/2008/03/12/lo_scanner_di_impronte_digitali_che_distingue_un_dito_vivo_da_unomorto.html'

opener=browser.open(url,timeout=2)

最佳答案

页面(由给定的 url 引用)以 refresh: 185 header 响应。这会导致 HTTPRefreshProcessor 休眠 185 秒;刷新同一页面; sleep ....(永远)。

您可以使用 set_handle_refresh 方法关闭 HTTPRefreshProcessor,如下所示:

browser.set_handle_refresh(False) # <-----
browser.open(url, timeout=2.0)

关于python mechanize 不会超时并卡在打开 url 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20376531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com