Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はhtmlページを解析するためにpython lxmlライブラリを使用しています:
import lxml.html # this might run indefinitely page = lxml.html.parse('http://stackoverflow.com/')
解析のタイムアウトを設定する方法はありますか?
オープナーとして使用しているように見えますurllib.urlopenが、これを行う最も簡単な方法は、ソケット ハンドラーのデフォルトのタイムアウトを変更することです。
urllib.urlopen
import socket timeout = 10 socket.setdefaulttimeout(timeout)
もちろん、これは簡単な解決策です。