import urllib.request
import re
vid="vbb35hm6m6da1wc"
cid=""
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
"Content-Type":"application/javascript",
}
opener=urllib.request.build_opener()
headall=[]
for key,value in headers.items():
item=(key,value)
headall.append(item)
opener.addheaders=headall
urllib.request.install_opener(opener)
for j in range(0,100):
#爬去当前页面
print("第"+str(j)+"页")
thisurl='https://video.coral.'
data=urllib.request.urlopen(thisurl).read().decode("utf-8")
titlepat='"title":"(.*?)","abstract":"(.*?)"'
commentpat='"content":"(.*?)"'
titleall=(titlepat,re.S).findall(data)
commentall=(commentpat,re.S).findall(data)
lastpat='"last":"(.*?)"'
cid=(lastpat,re.S).findall(data)[0]
for i in range(0,len(titleall)):
try:
print("评论标题是:"+eval('u"'+titleall[i]+'"'))
print("评论标题是:"+eval('u"'+commentall[i]+'"'))
print("------")
except Exception as err:
print(err)
[此贴子已经被作者于2019-9-14 20:29编辑过]