美文网首页
爬虫随机浏览器识别

爬虫随机浏览器识别

作者: 鲸随浪起 | 来源:发表于2019-01-20 17:26 被阅读0次
    import random
    import requests
    headers = {}
    user_agent_list = ["Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
                        "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
                        "Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/61.0",
                        "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
                        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36",
                        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
                        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
                        "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15",
                        ]
    headers['User-Agent'] = random.choice(user_agent_list)
    print(headers)
    url = 'https://www.xd0.com/'
    response = requests.get(url,headers = headers)
    cookiejar = response.cookies
    cookiedict = requests.utils.dict_from_cookiejar(cookiejar)
    print(cookiedict)
    for key,value in cookiedict.items():
        cookie = key+'='+value
        headers['Cookie'] = cookie
    headers['Accept-Language'] = 'zh-CN,zh;q=0.9'
    print(headers)
    

    相关文章

      网友评论

          本文标题:爬虫随机浏览器识别

          本文链接:https://www.haomeiwen.com/subject/fnaxjqtx.html