python爬虫基本示例
来源:互联网 发布:仿网易彩票源码 编辑:程序博客网 时间:2024/04/27 19:27
import requestsfrom bs4 import BeautifulSoupresponse=requests.get('http://www.autohome.com.cn/news/')# print(response.text)# with open('autohome_news','wb') as f:# f.write(response.content)with open('autohome_new_txt','r',encoding='utf-8') as f: data=f.read()# print(data)soup=BeautifulSoup(data,'html.parser')tag=soup.find(name='div',attrs={'id':'auto-channel-lazyload-article'})# print(tag)li_list=tag.find_all('li')# print(li_list[0].find(name='h3').text) #获取到标题对象 .text获取对象中的文本for li in li_list: h3=li.find(name='h3') if not h3: continue print(h3.text) a_tag=li.find(name='a').get('href') #.get获取对象的属性名对应的值 # attrs_tag=li.find(name='a').attrs['href'] #效果同上 print(a_tag) print(li.find('p').text) img_usl=li.find('img').get('src') print(img_usl) res=requests.get('http:'+img_usl) with open ('xxx.jpg','wb') as f: f.write(res.content)
阅读全文
0 0
- python爬虫基本示例
- Python爬虫之Scrapy 1 stackoverflow示例,基本步骤
- Python 爬虫示例
- Python 爬虫项目示例
- python基本爬虫实现
- python爬虫基本数据类型
- Python爬虫基本使用
- python 爬虫 基本抓取
- python 爬虫的简单示例
- python数据爬虫示例一
- python爬虫入门1--爬虫基本结构
- python爬虫的基本技巧
- 爬虫之抽屉新热榜点赞基本示例
- 七月算法《python爬虫》第一课:Python爬虫小示例
- 百度贴吧爬虫python示例
- python基本输入输出代码示例
- 用Python制作简单的爬虫---爬虫基本思想
- python爬虫入门-urllib的基本用法
- POJ 2155 Matrix 二维树状数组 区间更新,单点查询
- php计算两个时间相差的天数、小时数、分钟数、秒数
- springdata mongodb 查询二(Aggregation)
- 已损坏打不开您应该推出磁盘映像
- SSH的自定义登陆过滤器
- python爬虫基本示例
- Java集合去重两种做法
- ubuntu部署homeland
- 颜色定位与偏斜扭转
- 中国共产党第十九次全国代表大会 (党的十九大)
- Python 的 type 和 object 之间是怎么一种关系?
- Android开发:Spinner下拉列表
- Hive的安装详解
- 学习心得