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

            網站爬蟲的時候,我們會受到一些反爬蟲阻礙,但是我們可以利用ip代理來沖破限制。常見比較多的有對IP地址的訪問次數限制,以及對UA的限制,我們可以同時將用戶代理池與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',

            ]

            ippools=[

            "163.125.70.22",

            "111.231.90.122",

            "121.69.37.6",

            ]

            def ua_ip(myurl):

            def ip(ippools,uapools):

            thisip=random.choice(ippools)

            print(thisip)

            thisua = random.choice(uapools)

            print(thisua)

            headers = ("User-Agent", thisua)

            proxy=urllib.request.ProxyHandler({"http":thisip})

            opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)

            opener.addheaders = [headers]

            urllib.request.install_opener(opener)

            for i in range(5):

            try:

            ip(ippools,uapools)

            url=myurl

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

            print(len(data))

            break

            except Exception as err:

            print(err)

            return data

            data=ua_ip("https://www.baidu.com/")

            fp=open("uaip.html","w",encoding="utf-8")

            fp.write(data)

            fp.close()

            封裝成模塊:

            把模塊拷貝到python目錄  

          同時使用用戶代理池與ip代理池

            使用:

            from uaip import *

            data=ua_ip("https://www.baidu.com/")

            fp=open("baidu.html","w",encoding="utf-8")

            fp.write(data)

            fp.close()

            以上我們就可以設置好同時使用用戶代理池跟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

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