python爬取三大运营商号码归属地
时间: 2023-10-05 12:06:15 浏览: 194
你可以使用Python来爬取三大运营商的号码归属地信息。下面是一个示例代码:
```python
import requests
def get_phone_location(phone_number):
url = f"http://www.ip138.com:8080/search.asp?mobile={phone_number}"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
response = requests.get(url, headers=headers)
response.encoding = "gbk"
html = response.text
start = html.find("卡号归属地") + 6
end = html.find("</td>", start)
location = html[start:end]
return location
# 示例调用
phone_number = "13812345678"
location = get_phone_location(phone_number)
print(f"号码 {phone_number} 的归属地是:{location}")
```
阅读全文