• Python_实战爬虫


    # -*- coding: utf-8 -*-
    __auther__ = "jiachaojun"
    __time__ = '2020/1/12 11:03'
    import requests
    from bs4 import BeautifulSoup
    # 以什么编码写的,也要以什么编码解出来
    # 1、python模拟浏览器向 https://www.autohome.com.cn/news/

    r1 = requests.get('https://www.autohome.com.cn/news/')
    print(r1.content)

    # 2.去字符串找我想要的东西 (先将二进制转换成字符串)
    data = r1.content.decode('gb2312')
    soup = BeautifulSoup(data,features='html.parser')
    container = soup.find(id='auto-channel-lazyload-article')
    li_list = container.find_all(name='li')
    for item in li_list:
    tag = item.find(name='h3')
    if not tag:
    continue
    img_url = "https:"+item.find(name='img').get('src')
    print(item.find(name='h3').text,img_url)
    print('===============================================')
    坚持这种真诚,那么总归能遇到良人。
  • 相关阅读:
    1-4 Autolayout
    1-3 UIScrollView
    lua 的语法糖
    javascript文档
    cocos2d 图片模糊
    a*寻路分析
    class按传递时分析
    mac 不再接受预览版提示
    OS X 10.11 El Capitan 三指拖动的开启方法
    mac系统卸载mono
  • 原文地址:https://www.cnblogs.com/jiaxiaozia/p/12182209.html
Copyright © 2020-2023  润新知