<listing id="fdftx"></listing>

        <address id="fdftx"></address>
        <address id="fdftx"><address id="fdftx"><nobr id="fdftx"></nobr></address></address>
        <address id="fdftx"><listing id="fdftx"><nobr id="fdftx"></nobr></listing></address>

        <address id="fdftx"><nobr id="fdftx"><meter id="fdftx"></meter></nobr></address><address id="fdftx"><th id="fdftx"><progress id="fdftx"></progress></th></address>

          [使用案例]通過使用ip代理騰訊視頻評論爬蟲案例

          發布時間:2020-05-24 關注熱度:°C

            對于專業的爬蟲工程師來說,掌握好爬蟲語言以及ip代理的配合使用,能夠爬取到不同網站的不同信息。今天我們來看看一個具體的爬蟲案例。

            如何爬取騰訊視頻的評論?下面跟著IP海來看看具體的操作步驟:

            在火狐瀏覽器打開騰訊視頻,比如https://v.qq.com/x/cover/j6cgzhtkuonf6te.html

            點擊查看更多解讀,這時fiddler會有一個js文件:

            

          騰訊視頻評論爬蟲案例

           

            里面的內容就是評論。

            找到一條評論轉一下碼:

            

          騰訊視頻評論爬蟲案例

           

            在火狐里ctrl+f看看有沒有這條評論。

            copy js文件的url。

            點擊查看更多評論,再觸發一個json,copy url

            分析兩個url:

            

          騰訊視頻評論爬蟲案例

           

            簡化一下網頁試試:https://video.coral.qq.com/filmreviewr/c/upcomment/j6cgzhtkuonf6te?reqnum=3&commentid=6227734628246412645

            通過分析,我們可以知道j6cg……是視頻id,reqnum是每次查看的評論數量,commentid是評論id

            https://video.coral.qq.com/filmreviewr/c/upcomment/【vid】?reqnum=【num】&commentid=【cid】

            單頁評論爬蟲

            有一些特殊字符比如圖片現在還不知道怎么處理……以后再說吧

            import urllib.request

            import re

            from uaip import *

            vid="j6cgzhtkuonf6te"

            cid="6227734628246412645"

            num="3" #每頁提取3個

            url="https://video.coral.qq.com/filmreviewr/c/upcomment/"+vid+"?reqnum="+num+"&commentid="+cid

            data=ua_ip(url)

            titlepat='"title":"(.*?)","abstract":"'

            commentpat='"content":"(.*?)",'

            titleall=re.compile(titlepat,re.S).findall(data)

            commentall=re.compile(commentpat,re.S).findall(data)

            # print(len(commentall))

            for i in range(len(titleall)):

            try:

            print("評論標題是:"+eval("u'"+titleall[i]+"'"))

            print("評論內容是:"+eval("u'"+commentall[i]+"'"))

            print('---------------')

            except Exception as err:

            print(err)

            翻頁評論爬蟲

            查看網頁源代碼可以發現last:后面的內容為下一頁的id

            import urllib.request

            import re

            from uaip import *

            vid="j6cgzhtkuonf6te"

            cid="6227734628246412645"

            num="3"

            for j in range(10): #爬取1~10頁內容

            print("第"+str(j+1)+"頁")

            url = "https://video.coral.qq.com/filmreviewr/c/upcomment/" + vid + "?reqnum=" + num + "&commentid=" + cid

            data = ua_ip(url)

            titlepat = '"title":"(.*?)","abstract":"'

            commentpat = '"content":"(.*?)",'

            titleall = re.compile(titlepat, re.S).findall(data)

            commentall = re.compile(commentpat, re.S).findall(data)

            lastpat='"last":"(.*?)"'

            cid=re.compile(lastpat,re.S).findall(data)[0]

            for i in range(len(titleall)):

            try:

            print("評論標題是:" + eval("u'" + titleall[i] + "'"))

            print("評論內容是:" + eval("u'" + commentall[i] + "'"))

            print('---------------')

            except Exception as err:

            print(err)

            對于短評(普通評論)方法類似,這里就不贅述了,看下面這個短評爬蟲代碼:

            將https://video.coral.qq.com/varticle/1743283224/comment/v2?callback=_varticle1743283224commentv2&orinum=10&oriorder=o&pageflag=1&cursor=6442954225602101929&scorecursor=0&orirepnum=2&reporder=o&reppageflag=1&source=132&_=1566363507957

            簡化成:https://video.coral.qq.com/varticle/1743283224/comment/v2?orinum=10&oriorder=o&pageflag=1&cursor=6442954225602101929

            import urllib.request

            import re

            from uaip import *

            vid="1743283224"

            cid="6442954225602101929"

            num="5"

            for j in range(10): #爬取1~10頁內容

            print("第"+str(j+1)+"頁")

            url="https://video.coral.qq.com/varticle/"+vid+"/comment/v2?orinum="+num+"&oriorder=o&pageflag=1&cursor="+cid

            data = ua_ip(url)

            commentpat = '"content":"(.*?)"'

            commentall = re.compile(commentpat, re.S).findall(data)

            lastpat='"last":"(.*?)"'

            cid=re.compile(lastpat,re.S).findall(data)[0]

            # print(len(gg))

            # print(len(commentall))

            for i in range(len(commentall)):

            try:

            print("評論內容是:" + eval("u'" + commentall[i] + "'"))

            print('---------------')

            except Exception as err:

            print(err)

            以上,我們就將騰訊視頻的評論內容給抓取下來了,大家可以自己練習看看效果。

           

          版權聲明:本文為IP海(iphai.cn)原創作品,未經許可,禁止轉載!

          Copyright © www.skldkt.com. All Rights Reserved. IP海 版權所有.
          IP海僅提供中國內IP加速服務,無法跨境聯網,用戶應遵守《服務條款》內容,嚴禁用戶使用IP海從事任何違法犯罪行為。
          ICP備案鄂ICP備19030659號-3 公安備案鄂公網安備42100302000141號 計算機軟件著作權證計算機軟件著作權證 ICP/EDI許可證ICP/EDI許可證:鄂B2-20200106

          微信掃一掃咨詢
          国产福利第一页