爬取汽车之家

import requests
from bs4 import BeautifulSoup
response = requests.get(‘https://www.autohome.com.cn/news/‘)
response.encoding = ‘gbk‘
soup = BeautifulSoup(response.text,"html.parser")
div =soup.find(name=‘div‘,id=‘auto-channel-lazyload-article‘)
li_list = div.find_all(name=‘li‘)
for li in li_list:
    h3 = li.find(name=‘h3‘)
    a = li.find(name=‘a‘)
    p =li.find(name=‘p‘)
    img = li.find(name=‘img‘)
    if not h3:
        continue
    print(h3.text)
    print(a.attrs[‘href‘])
    print(p.text)
    img_url = ‘https:‘+ img.attrs[‘src‘]
    img_response = requests.get(img_url)
    file_name = img_url.rsplit(‘/‘,maxsplit=1)[1]
    with open(file_name,‘wb‘) as f:
        f.write(img_url.content)
    print(‘======================‘)

  

原文地址:https://www.cnblogs.com/zhanglin123/p/9283361.html

时间: 2024-07-30 12:19:57

爬取汽车之家的相关文章

python3 爬取汽车之家所有车型操作步骤

题记: 互联网上关于使用python3去爬取汽车之家的汽车数据(主要是汽车基本参数,配置参数,颜色参数,内饰参数)的教程已经非常多了,但大体的方案分两种: 1.解析出汽车之家某个车型的网页,然后正则表达式匹配出混淆后的数据对象与混淆后的js,并对混淆后的js使用pyv8进行解析返回正常字符,然后通过字符与数据对象进行匹配,具体方法见这位园友,传送门:https://www.cnblogs.com/my8100/p/js_qichezhijia.html (感谢这位大神前半部分的思路) 2.解析出

爬取汽车之家新闻

a.首先伪造浏览器向某个地址发送HTTP请求,获取返回的字符串 import requestsresponse=requests.get(url='地址')#get请求 response.content #内容 response.encoding=apparent_encoding #检测编码形式,并设置编码 response.text #自动转码 b.通过Beautifulsoup4解析HTML格式字符串 from bs4 import BeautifulSoup soup = Beautif

爬取汽车之家新闻图片的python爬虫代码

import requestsfrom bs4 import BeautifulSouprespone=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

py 爬取汽车之家新闻案例

``` import requests from bs4 import BeautifulSoup response = requests.get("https://www.autohome.com.cn/news/") # 1. content /text 的区别 # print(response.content) # content 拿到的字节 response.encoding = 'gbk' # print(response.text) # text 拿到的文本信息 soup

scrapy爬虫之爬取汽车信息

scrapy爬虫还是很简单的,主要是三部分:spider,item,pipeline 其中后面两个也是通用套路,需要详细解析的也就是spider. 具体如下: 在网上找了几个汽车网站,后来敲定,以易车网作为爬取站点 原因在于,其数据源实在是太方便了. 看这个页面,左边按照品牌排序,搜索子品牌,再挨个查看信息即可 按照通常的思路,是需要手动解析左边这列表 找出每个品牌的链接页面 结果分析源码发现,网站直接通过js生成的导航栏,直接通过这个链接生成的json即可获得所有的信息 http://api.

爬取IT之家业界新闻

爬取站点  https://it.ithome.com/ityejie/ ,进入详情页提取内容. 1 import requests 2 import json 3 from lxml import etree 4 from pymongo import MongoClient 5 6 url = 'https://it.ithome.com/ithome/getajaxdata.aspx' 7 headers = { 8 'authority': 'it.ithome.com', 9 'met

python 爬虫爬取几十家门店在美团外卖上的排名,并插入数据库,最后在前端显示

爬虫脚本: #!/usr/bin/env python # encoding: utf-8 """ @version: ?? @author: phpergao @license: Apache Licence  @file: meituan_paiming.py @time: 2016/8/1 15:16 """ import urllib,json,re import urllib.parse import http.cookiejar im

03:requests与BeautifulSoup结合爬取网页数据应用

1.1 爬虫相关模块命令回顾 1.requests模块 1. pip install requests 2. response = requests.get('http://www.baidu.com/ ')            #获取指定url的网页内容 3. response.text                                                                                #获取文本文件 4. response.cont

Python爬虫入门教程 64-100 反爬教科书级别的网站-汽车之家,字体反爬之二

说说这个网站 汽车之家,反爬神一般的存在,字体反爬的鼻祖网站,这个网站的开发团队,一定擅长前端吧,2019年4月19日开始写这篇博客,不保证这个代码可以存活到月底,希望后来爬虫coder,继续和汽车之间对抗. CSDN上关于汽车之家的反爬文章千千万万了,但是爬虫就是这点有意思,这一刻写完,下一刻还能不能用就不知道了,所以可以一直不断有人写下去.希望今天的博客能帮你学会一个反爬技巧. 今天要爬去的网页 https://car.autohome.com.cn/config/series/59.htm