import requests
from bs4 import BeautifulSoup
respone=requests.get(\'https://www.autohome.com.cn/news/\')
respone.encoding=\'gbk\'
# print(respone.text)
soup=BeautifulSoup(respone.text,\'html.parser\')
div=soup.find(name=\'div\',attrs={\'id\':\'auto-channel-lazyload-article\'})
li_list=div.find_all(name=\'li\')
i=1
for li in li_list:
print(\'pro:\',i)
title=li.find(name=\'h3\')
if not title:
continue
p=li.find(name=\'p\')
a=li.find(name=\'a\')
img=li.find(name=\'img\')
print(title.text)
print(p.text)
print(\'https:\'+a.attrs.get(\'href\'))
print(\'https:\'+img.get(\'src\')) #img.get==img.attrs.get
#请求下载图片
src=\'https:\'+img.get(\'src\')
file_name=src.rsplit(\'/\',maxsplit=1)[1]
with open(file_name,\'wb\') as f:
ret=requests.get(src)
f.write(ret.content)
相关文章:
- 爬虫之爬汽车之家 2021-12-15
- 汽车之家网站为例-爬虫的编写,爬取图片 2021-07-14
- 汽车之家 爬虫 2021-12-05
- java爬虫入门--用jsoup爬取汽车之家的新闻 - demo例子集 2021-12-05
- Python 爬虫-----汽车之家字体反爬 2021-12-09
- 爬虫之汽车之家 2021-12-05
- python 爬虫 汽车之家车辆参数反爬 2021-12-05
- Python 爬虫实例(15) 爬取 汽车之家(汽车授权经销商) 2021-12-05