手机号码归属地的自动查询.py(亲测有效)
import requests url = "http://m.ip138.com/sj.asp?mobile=" kv = {'user-agent':'Mozilla/5.0'} # 请求头 try: r = requests.get(url + '电话号码',headers=kv) print(r.raise_for_status()) r.encoding = r.apparent_encoding print(r.text) except: print("爬取失败")