python爬虫入门_在百度搜索手机归属地
2023-06-13 09:15:04 时间
枚举手机号,在百度搜索手机归属地
工具
- requests http库
- BeautifulSoup html解析库
代码
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
headersPara = { #伪装浏览器信息
'Connection': 'Keep-Alive',
'Accept': 'text/html, application/xhtml+xml, */*',
'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/6.1 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
}
url="https://www.baidu.com/s"
f=open('./phonenumber.txt','w')
for i in range(111,119):
word="13363460"+str(i)
print(i)
f.write(word+' ')
data={
'wd':word,
'ie':'utf-8'
}
#发送get请求,添加可选参数params和headers
response =requests.get(url=url,params=data,headers=headersPara)
response.encoding="utf-8"
#获取html网页
html=response.text
#使用lxml解析html页面成一棵树,返回给soup
soup=BeautifulSoup(html,'lxml')
#data=soup.select('#main > div > div.result-right > div.c-border.op_fraudphone_container > div > div.c-span21.c-span-last > div.op_fraudphone_row')
#用select选择需要的标签,前面加.表示类名,可用空格组合过滤条件
data=soup.select('.c-gap-bottom-small span')
if data and data[1]:
#print(data[1].get_text())
#print(data[1].get('href'))
#获取标签内的文本
f.write(data[1].get_text())
f.write('\n')
f.close()
参考
欢迎与我分享你的看法。 转载请注明出处:http://taowusheng.cn/
相关文章
- python中导入numpy为什么错误_pycharm安装配置教程
- python json.loads()、json.dumps()和json.dump()、json.load()区别
- python中pygame怎么安_Python中pygame安装方法图文详解
- python dll注入 网络_dll注入
- python编程前景_Python前景如何,学完后可以从事方向?
- Python对MySQL操作
- Python抓取数据_python抓取游戏数据
- 【说站】python变量赋值的操作
- pycharm怎么配置python环境anaconda_pycharm环境变量配置Anaconda
- python requests 关闭提示警告
- python判断文件后缀_Python 判断文件后缀是否被篡改
- vim 搜索字符串_python查找字符串位置
- python程序化交易实例-用 Python 实现你的量化交易策略「建议收藏」
- Python 实用技能 RAPIDS | 利用 GPU 加速数据科学工作流程
- Win10 环境下安装Tesseract-OCR与Python集成识别
- Python中的递归与二分查找
- python-Python与SQLite数据库-处理SQLite查询结果(二)
- python-Django-表单验证(一)
- Linux(Ubuntu)系统安装Python
- 用Python多线程抓取并验证代理详解编程语言
- Python学习:6.python内置函数详解编程语言
- Python 缓存服务详解编程语言
- 在Linux上学习Python——你的编程之路(linux学python)
- 通过 VSCode RTOS 插件使用 Python 为物联网系统编写程序
- 机器学习年度 20 大开源项目花落谁家?(Python 版)
- Python实现Oracle数据库连接(python连接oracle数据库)
- 在Linux系统中使用Python编程语言(linux中python)