add_read_times.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:Python-Spider 作者: NoharaHiroshi 项目源码 文件源码
def Proxy_read(proxy_ip_list, user_agent_list):
    proxy_ip = random.choice(proxy_ip_list)
    print('????ip?%s'%proxy_ip)
    user_agent = random.choice(user_agent_list)
    print('????user_agent?%s'%user_agent)
    sleep_time = random.randint(1,5)
    print('?????%s' %sleep_time)
    time.sleep(sleep_time)
    print('????')
    headers = {
            'Host': 'www.baidu.com',
            'User-Agent': user_agent,
            'Accept': r'application/json, text/javascript, */*; q=0.01',
            'Referer': r'http://www.cnblogs.com/Lands-ljk/p/5589888.html',
            }

    proxy_support = request.ProxyHandler({'http':proxy_ip})
    opener = request.build_opener(proxy_support)
    request.install_opener(opener)

    req = request.Request(r'http://www.cnblogs.com/mvc/blog/ViewCountCommentCout.aspx?postId=5589888',headers=headers)
    try:
        html = request.urlopen(req).read().decode('utf-8')
    except Exception as e:
        print('?????')
    else:
        print('OK!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号