动态加载ajax 腾讯视频评论

import urllib
import urllib2
import os
import requests
import re
import json

sns_url = 'http://sns.video.qq.com/fcgi-bin/video_comment_id?otype=json&op=3&vid='

url = 'http://v.qq.com/cover/q/qviv9yyjn83eyfu.html?vid=n0016ibg4eb'

head = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36'}

QQTV = 'http://coral.qq.com/article/%s/comment?commentid=0&reqnum=10'
def find_html():
    response = urllib2.urlopen(url)
    html = response.read();
    return html
def find_vid():
    response = find_html()
    #vid = re.search('vid:"(.*?)",',response.body,re.S).group(1)
    vid = re.search('vid:"(.*?)",',str(response),re.S).group(1)
    vid_url = sns_url + str(vid)
    return vid_url
def find_fin():
    qq_url = find_vid()
    response  = urllib2.urlopen(qq_url)
    html = response.read()
    comment = re.search('"comment_id":"(.*?)",',str(html),re.S).group(1)
   # print(comment)
    fin_html = QQTV % comment
    return fin_html

def get_message():
    comment_url = find_fin()
    print(comment_url)
    json_comment = requests.get(comment_url,headers = head).content
    json_Dict = json.loads(json_comment)
    json_Data = json_Dict['data']
    json_comment = json_Data['commentid']
    for each in json_comment:
        print(each['content'])
if __name__ == '__main__':
    get_message()
原文地址:https://www.cnblogs.com/chenyang920/p/5078251.html