urllib.request.urlopen不停地

2024-03-28 17:01:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过使用urllib.request.open文件. 你知道吗

我不知道为什么我的代码没有停止。你知道吗

from urllib.request import urlopen

url = "https://google.com"
try:
    page = urlopen(url)
    f = open("google.html","wb")
    f.write(page.read())
except:
    print("Error")

但超时后,它收到了源代码。你知道吗

from urllib.request import urlopen

url = "https://google.com"
try:
    page = urlopen(url, timeout=0.1)
    f = open("google.html","wb")
    f.write(page.read())
except:
    print("Error")

Tags: fromhttpsimportcomurlrequesthtmlgoogle