import urllib
from urllib import request
import time
def GetInfo(url):
headers = {'Host':'blog.csdn.net','Upgrade-Insecure-Requests':'1','User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 115Browser/8.4.0','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Accept-Encoding':'deflate','Accept-Language':'zh-CN,zh;q=0.8','Cookie':'uuid_tt_dd=5534972241583295096_20170723; Hm_lvt_ae0da6ae5315ea17b7070248c46e786d=1500801364; bdshare_firstime=1500801363575; __message_sys_msg_id=0; __message_gu_msg_id=0; __message_cnel_msg_id=0; __message_in_school=0; uuid=251f31c7-a055-4dbd-a1e2-860d7bc69162; avh=77069612; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1502173673,1502173724,1502266846,1502360077; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1502360077; dc_tos=ougsgd; dc_session_id=1502360077644_0.7990083903386638','If-None-Match':'W/"f75bf97f893364efa173f6d16d06ff15"'}
data = None
try:
req = urllib.request.Request(url,data,headers)
res = urllib.request.urlopen(req)
html = res.read().decode("utf-8")
#print(html)
#input()
except:
print('error')
html = ''
return html
if __name__ == '__main__':
while True:
url = 'http://blog.csdn.net/neejack/article/details/77426425'
html = GetInfo(url)
try:
SP = html.index('"阅读次数">')+7
EP = html.index('人阅读')
cnt = html[SP:EP]
print('c',cnt)
except:
print('')
time.sleep(180)
xxxxxxxxxx
最新推荐文章于 2024-06-12 11:58:26 发布