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)

最新文章

  1. android 两种实现计时器时分秒的实现,把时间放在你的手中~
  2. easyUI 复选框批量操作
  3. js反射机制
  4. 活动组件(三):Intent
  5. Func系列4:其他功能
  6. C\C++编程中:相对路径+绝对路径
  7. solr英文使用的基本分词器和过滤器配置
  8. HDU4553 约会安排
  9. PHP Sessions
  10. win7 安装 vagrant + centos + virtualbox
  11. webpack中dev-server不写contentBase时如何设置可以显示页面并且加载js
  12. 《java.util.concurrent 包源码阅读》27 Phaser 第一部分
  13. window 7 安装Jmeter并配置https录制脚本
  14. 【原创】Linux基础之curl
  15. vue中router使用keep-alive缓存页面的注意事项
  16. 搭建EOS环境
  17. 关于PHP程序员技术职业生涯规划
  18. 腾讯云Badjs镜像使用入门
  19. os模块学习+open行数
  20. Discuptor入门(二)-实例

热门文章

  1. hadoop关闭安全模式
  2. Java xml和map,list格式的转换-摘抄
  3. Python一等函数
  4. Burpsuite 2.0.11 Beta 破解版下载
  5. 一种关闭Windows 8.1 Windows Defender的简单办法
  6. [Cogs] 线型网络
  7. cropbox.js 头像裁剪插件
  8. C++类中函数(构造函数、析构函数、拷贝构造函数、赋值构造函数)
  9. 【java设计模式】-06原型模式
  10. csp-s模拟80(b)