<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-07-09 關注熱度:°C

            看到網上關于爬蟲的教程,有一個詞會出現得非常頻繁,不知道大家有沒有留意到,那就是ip代理池。今天IP海就要來給大家介紹ip代理池有什么用。

          用戶ip代理池的作用

            什么是用戶ip代理池?

            用戶代理池就是將不同的用戶代理組建成為一個池子,隨后隨機調用。

            作用:每次訪問代表使用的瀏覽器不一樣

            import urllib.request

            import re

            import random

            uapools=[

            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',

            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER',

            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1',

            'Mozilla/5.0 (Windows; U; Windows NT 6.1; ) AppleWebKit/534.12 (KHTML, like Gecko) Maxthon/3.0 Safari/534.12',

            ]

            def ua(uapools):

            thisua=random.choice(uapools)

            print(thisua)

            headers=("User-Agent",thisua)

            opener=urllib.request.build_opener()

            opener.addheaders=[headers]

            urllib.request.install_opener(opener)

            for i in range(10):

            ua(uapools)

            thisurl="https://www.qiushibaike.com/text/page/"+str(i+1)+"/";

            data=urllib.request.urlopen(thisurl).read().decode("utf-8","ignore")

            pat='<div class="content">.*?<span>(.*?)</span>.*?</div>'

            res=re.compile(pat,re.S).findall(data)

            for j in range(len(res)):

            print(res[j])

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

            簡單的來說,ip代理池就是將可用的ip代理集中在一起,讓它們配置在我們爬蟲的程序當中,當一個IP失效之后,馬上又另外一個IP接著使用。

           

          版權聲明:本文為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

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