Python爬虫入门之查询ip地址
import requests
url = "http://m.ip138.com/ip.asp?ip="
IpAddress = input("Please input the ip address\n")
try:
r = requests.get(url+IpAddress)
r.raise_for_status()
r.encoding = r.apparent_encoding
print(r.text[-400:-150])#截取有用的部分输出
except:
print("ERROR")