分享一個擷取代理ip的python函數

來源:互聯網
上載者:User

標籤:

分享一個擷取代理ip的python函數

123456789101112131415161718 #coding:utf-8from bs4 import BeautifulSoupimport requestsimport random def getproxyip():headers = {‘Accept‘:‘text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8‘,‘Accept-Encoding‘:‘gzip,deflate,sdch‘,‘Host‘:‘www.ip-adress.com‘,‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0‘} proxy_url = ‘http://www.ip-adress.com/Proxy_Checker/‘proxy_req = requests.get(proxy_url,headers=headers)proxy_soup = BeautifulSoup(proxy_req.text)proxy_ip = proxy_soup.find_all(‘tr‘,{‘class‘:‘yellow‘})return proxy_ip[random.randrange(0,4)].td.text

 

 

 

python編寫的自動擷取代理IP列表的爬蟲

#/usr/local env python
#coding utf-8
import os
import urllib
from bs4 import BeautifulSoup

def log():
    f=open("f:\daili.txt",‘a‘)
    f.write(ip)
    f.close()

def fenxi():
    page = urllib.urlopen(url)
    data = page.read()
    soup=BeautifulSoup(data)
    #print soup
    list=soup.find_all(‘span‘)
    for i in list:
        #print i.get_text()
        global ip
        ip= i.get_text()
        s="\n".join(ip.split(‘#‘))
        print s
        log()  
for i in range(1,10):
    if i==1:
        url = ‘http://www.youdaili.cn/Daili/http/556.html‘
        print url
        fenxi()
    else:
        url = ‘http://www.youdaili.cn/Daili/http/556_‘+str(i)+‘.html‘
        print url
        fenxi()
        
       運行結果:
||||||||IP知識庫最新代理IPwww.Youdaili.Cn07-09免費代理國內外http代理ip地址1.186.200.211:[email protected]#印度

2.135.238.92:[email protected]#哈薩克

2.181.177.7:[email protected]#伊朗

2.183.155.2:[email protected]#伊朗

分享一個擷取代理ip的python函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.