zoukankan      html  css  js  c++  java
  • spider_使用随机User-Agent库, 爬取笔趣阁万古天帝章节目录_(fake_useragent)

    """
    使用随机User-Agent库,
    爬取笔趣阁万古天帝章节目录

    """

    import requests
    from fake_useragent import FakeUserAgent
    import random
    import chardet
    def biquge():
    # 定义url,
    url = "https://www.biqudao.com/bqge25289/"

    # 使用第三方库随机获得一个userAgent
    userAgent = FakeUserAgent().random
    print(userAgent)
    print(type(userAgent))

    # 传入字典中
    headers= {
    "User-Agent":userAgent
    }
    # 返回字节流数据
    bytesHtml=requests.get(url,headers=headers).content
    # 判断网页编码格式,返回一个字典
    res=chardet.detect(bytesHtml)
    # 解码
    html=bytesHtml.decode(res["encoding"])
    print(html)

    biquge()
    人生苦短,我用python!
  • 相关阅读:
    排序
    wine-qq 安装
    逆元模板
    最长上升子序列
    SGU[115] Calendar
    SGU[123] The sum
    SGU[105] Div 3
    SGU[102] Coprimes
    SGU[100] A+B
    poj-1325-Machine Schedule
  • 原文地址:https://www.cnblogs.com/YangQingHong/p/10978251.html
Copyright © 2011-2022 走看看