分享一个获取代理ip的python函数

本文提供了一个使用Python编写的函数,用于从特定网站自动获取代理IP列表。

分享一个获取代理ip的python函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#coding:utf-8
from bs4 import BeautifulSoup
import requests
import 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_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:8080@HTTP#印度

2.135.238.92:9090@HTTP#哈萨克斯坦

2.181.177.7:8080@HTTP#伊朗

2.183.155.2:8082@HTTP#伊朗

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值