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")

posted @ 2018-02-09 15:44  Assassin_poi君  阅读(406)  评论(0编辑  收藏  举报