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!')
评论列表
文章目录