手机号码归属地的自动查询.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("爬取失败")

 

posted on 2020-12-30 21:12  打篮球的Curry  阅读(540)  评论(0编辑  收藏  举报