赞
踩
url = "https://www.ip138.com/iplookup.asp?ip=222.222.64.194&action=2"
try:
r = requests.get(url)
print(r.status_code)
r.raise_for_status()
r.encoding = r.apparent_encoding
print(r.text)
except:
print("爬取失败")
该网址保护较好,没法直接通过链接访问到该网站
添加请求头
kv = {’ user-agent’: ‘Mozilla/ 5.0’}
r = requests.get(ur1, headers=kv)
url = "https://www.ip138.com/iplookup.asp?ip=222.222.64.194&action=2"
try:
kv = {'user-agent': 'Mozilla/5.0'}
r = requests.get(url, headers=kv)
print(r.status_code)
r.raise_for_status()
r.encoding = r.apparent_encoding
print(r.text)
except:
print("爬取失败")
状态码显示200,访问成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。