乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      第一個(gè)爬蟲(chóng)——斗魚(yú)分類下的人氣排行

       印度阿三17 2020-02-29
      from urllib import request
      from io import BytesIO
      import gzip
      import re
      
      class Spider():
      	def __init__(self):
      		self.url='https://www.douyu.com/g_LOL'
      		self.root_pattern='<div class="DyListCover-info"><span class="DyListCover-hot is-template"><svg><use xlink:href="#icon-hot_8a57f0b"></use></svg>([\s\S]*?)</h2></div>'
      		self.number_pattern='([\s\S]*?)</span>'
      		self.name_pattern='</use></svg>([\s\S]*?)'
      
      	def __fetch_content(self):
      		headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'}
      		page1=request.Request(self.url,headers=headers)
      		r=request.urlopen(page1)#加入瀏覽器信息
      		htmls=r.read()#獲取字節(jié)碼
      		buff=BytesIO(htmls)
      		f=gzip.GzipFile(fileobj=buff)
      		htmls=f.read().decode('utf-8')#數(shù)據(jù)被壓縮過(guò),我們要對(duì)數(shù)據(jù)進(jìn)行處理。
      		return htmls
      
      	def __analysis(self,htmls):
      		root_htmls=re.findall(self.root_pattern,htmls)
      		anchors=[]
      		for origin_html in root_htmls:
      			new_html=origin_html.replace('</span><h2 class="DyListCover-user is-template"><svg><use xlink:href="#icon-user_c95acf8"></use></svg>','')
      			anchors.append(new_html)
      		print(anchors)
      
      	def go(self):
      		htmls=self.__fetch_content()
      		self.__analysis(htmls)
      		
      spider=Spider()
      spider.go()

      以前覺(jué)得爬蟲(chóng)很難,完成了一個(gè)小目標(biāo)之后,覺(jué)得有點(diǎn)小放松。

      但內(nèi)心卻似乎感覺(jué)很朦朧。

      只是冰山一角而已。

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多