import urllib.request
#如果我们的网页常时间未响应,系统判断超时,无法爬取
for i in range(1,100):
#timeout (设置)判断超时时间
try:
response=urllib.request.urlopen('http://baidu.com',timeout=0.5)
print(len(response.read().decode('utf-8')))
except:
print('请求超时,请继续下一个爬取')
import urllib.request
#如果我们的网页常时间未响应,系统判断超时,无法爬取
for i in range(1,100):
#timeout (设置)判断超时时间
try:
response=urllib.request.urlopen('http://baidu.com',timeout=0.5)
print(len(response.read().decode('utf-8')))
except:
print('请求超时,请继续下一个爬取')