美文网首页
爬微博序列号

爬微博序列号

作者: HouserLin | 来源:发表于2016-07-06 00:34 被阅读81次
    # -*- coding:utf-8 -*-
    import requests
    import re
    import time
    class weibo():
        def __init__(self):
            self.weibo = []
        def get_page1(self, url):
            cookies = {}
            cookie = 'SINAGLOBAL=2777936565689.7427.1466425410359; wb_bub_hot_1860241872=1; wb_g_minivideo_1860241872=1; SSOLoginState=1467537363; YF-Ugrow-G0=b02489d329584fca03ad6347fc915997; YF-V5-G0=b188043973f8ae1849ba6cd9ae007290; _s_tentry=-; Apache=7162702707573.771.1467538108120; ULV=1467538108217:14:3:1:7162702707573.771.1467538108120:1467373335174; YF-Page-G0=3d55e26bde550ac7b0d32a2ad7d6fa53; WBStore=8ca40a3ef06ad7b2|undefined; un=582602426@qq.com; wvr=6; gsid_CTandWM=4ubUCpOz5xZW3mcuHYb0I7NVTe4; SCF=AsG32LL5L-tXhp-r1nkoX4WKVRR90O-T9ecxTNXSsvXewAtX4tSPpWx4_jfwlYNTuRw6BS9oxKaK4muBwsqe3PQ.; SUB=_2A256f6BfDeTxGedG7VIT9C_EzD6IHXVZDJaXrDV8PUJbmtBeLRCikW8XOCjEMbO9_BI_WqTmNAYyV6Avlg..; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WFMl0_0K_GpCB8HR3kxdz7m5JpX5o2p5NHD95Qp1hq7eoBp1hMEWs4DqcjHi--ci-zfi-24i--ciKnRiK.7KsLV; SUHB=05iLVRXO83IiPd; UOR=,,link.zhihu.com'
            for line in cookie.split(';'): 
        #其设置为1就会把字符串拆分成2份 
                name,value=line.strip().split('=',1) 
                cookies[name]=value 
            html = requests.get(url, cookies = cookies).text
            #f.write(html.text.encode('utf-8'))
            xunliehaos = re.findall(r'\w+-\w+-\w+-\w+', html, re.S)
            for i in xunliehaos:
                self.weibo.append(i)
        def get_page2(self, url):
            cookies = {}
            cookie = 'SINAGLOBAL=2777936565689.7427.1466425410359; wb_bub_hot_1860241872=1; wb_g_minivideo_1860241872=1; SSOLoginState=1467537363; YF-Ugrow-G0=b02489d329584fca03ad6347fc915997; YF-V5-G0=b188043973f8ae1849ba6cd9ae007290; _s_tentry=-; Apache=7162702707573.771.1467538108120; ULV=1467538108217:14:3:1:7162702707573.771.1467538108120:1467373335174; YF-Page-G0=3d55e26bde550ac7b0d32a2ad7d6fa53; WBStore=8ca40a3ef06ad7b2|undefined; un=582602426@qq.com; wvr=6; gsid_CTandWM=4ubUCpOz5xZW3mcuHYb0I7NVTe4; SCF=AsG32LL5L-tXhp-r1nkoX4WKVRR90O-T9ecxTNXSsvXewAtX4tSPpWx4_jfwlYNTuRw6BS9oxKaK4muBwsqe3PQ.; SUB=_2A256f6BfDeTxGedG7VIT9C_EzD6IHXVZDJaXrDV8PUJbmtBeLRCikW8XOCjEMbO9_BI_WqTmNAYyV6Avlg..; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WFMl0_0K_GpCB8HR3kxdz7m5JpX5o2p5NHD95Qp1hq7eoBp1hMEWs4DqcjHi--ci-zfi-24i--ciKnRiK.7KsLV; SUHB=05iLVRXO83IiPd; UOR=,,link.zhihu.com'
            for line in cookie.split(';'): 
        #其设置为1就会把字符串拆分成2份 
                name,value=line.strip().split('=',1) 
                cookies[name]=value 
            html1 = requests.get(url, cookies = cookies).text
            new = re.findall(r'\w+-\w+-\w+-\w+', html1, re.S)[1]
            if new not in self.weibo:
                print new
            
    url = 'http://weibo.com/p/1005051860241872/home?from=page_100505_profile&wvr=6&mod=data&is_all=1'
    weib = weibo()
    while 1:
        weib.get_page1(url)
        time.sleep(15)
        weib.get_page2(url)
    
    
    

    相关文章

      网友评论

          本文标题:爬微博序列号

          本文链接:https://www.haomeiwen.com/subject/nqckjttx.html