|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Python 查询固定电话位置
- from requests import get
- from bs4 import BeautifulSoup as BS
- def open_url(url):
- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}
- res = get(url, headers = headers)
- return res
- def get_phone(res):
- soup = BS(res.text, "html.parser")
- target = soup.find_all("td", bgcolor="#FFFFFF", style="font-size:16px;")
- print("电话号码:" + target[0].text)
- print("归属地: " + target[1].text)
-
- def main():
- while True:
- phone = input("请输入电话号码(输入的格式如:010-86551122 或 01086551122): ")
- if phone == "Q!":
- break
- url = 'https://tel.51240.com/%s__tel/' % phone
- res = open_url(url)
- get_phone(res)
- if __name__ == "__main__":
- main()
复制代码 |
|