利用requests库获取代理,用Beautiful库解析网页筛选ip

# -*- coding: utf- -*-
import requests
from bs4 import BeautifulSoup
from threading import Thread headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0'} #定义获取IP函数
def get_ip():
#写入txt
write_ip = open('get_ip.txt', 'w')
for page in range(, ):
url = 'http://www.xicidaili.com/nn/%s' % page
r = requests.get(url, headers=headers,timeout=) # 用beautifulsoup库解析网页
soup = BeautifulSoup(r.content, 'lxml')
trs = soup.find('table', id='ip_list').find_all('tr') for tr in trs[:]:
tds = tr.find_all('td')
ip = tds[].text.strip()
port = tds[].text.strip()
write_ip.write('%s\n'%(ip+':'+port))
write_ip.close()
print('done') get_ip()

python获取代理IP的更多相关文章

  1. python获取代理IP并测试是否可用

    # coding: utf-8 import urllib2 import re import time def getDL(page): url = 'http://www.xicidaili.co ...

  2. python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客

    python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客 undefined Python多线程抓取代理服务器 | Linux运维笔记 undefined java如 ...

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

    分享一个获取代理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 Beaut ...

  4. python爬虫之反爬虫(随机user-agent,获取代理ip,检测代理ip可用性)

    python爬虫之反爬虫(随机user-agent,获取代理ip,检测代理ip可用性) 目录 随机User-Agent 获取代理ip 检测代理ip可用性 随机User-Agent fake_usera ...

  5. Python学习笔记六(免费获取代理IP)

    为获取网上免费代理IP,闲的无聊,整合了一下,免费从三个代理网站获取免费代理IP,目的是在某一代理网站被限制时,仍可从可以访问的其他网站上获取代理IP.亲测可用哦!^_^  仅供大家参考,以下脚本可添 ...

  6. Python3.x:获取代理ip以及使用

    Python3.x:获取代理ip以及使用 python爬虫浏览器伪装 #导入urllib.request模块 import urllib.request #设置请求头 headers=("U ...

  7. python获取公网ip,本地ip及所在国家城市等相关信息收藏

    python获取公网ip的几种方式       from urllib2 import urlopen   my_ip = urlopen('http://ip.42.pl/raw').read() ...

  8. python获取公网ip的几种方式

    python获取公网ip的几种方式 转 https://blog.csdn.net/conquerwave/article/details/77666226 from urllib2 import u ...

  9. python检验代理ip是否可用、代理ip检验

    python检验代理ip是否可用.代理ip检验 安装相关模块: pip install requests 验证代理IP是否可用脚本: import random import telnetlib im ...

随机推荐

  1. python+opencv 运行环境搭建

    1:安装pycharm,验证码你懂的 2:安装python3.5以上,或3.6,python2和3 的版本差异还蛮大 3:安装opencv,如下图 以上是方法一,还有之中方法是下载whl文件再手动安装 ...

  2. FireFox(火狐)浏览器的相关问题

    如何加快FireFox(火狐)浏览器浏览网页速度 大部分网页加载缓慢的原因:1.宽带连接.网速不稳定2.浏览器本身问题,如果多开窗口浏览会占大量内存,而且磁盘空间没有做过优化,就这样电脑资源不够用,也 ...

  3. pseudotime专题

    review:Computational Methods for Trajectory Inference from Single-Cell Transcriptomics Tools/Algorit ...

  4. ubuntu16.04+cuda8.0+gpu

    安装完ubuntu系统之后,在学校的环境下,联网需要安装mentohust. 参考: http://www.cnblogs.com/alexanderkun/p/6905604.html http:/ ...

  5. WPF打印涉及到的关键类

    DocumentViewer--->FixedDocument----> PageContent  ---->FixedPage

  6. English trip V1 - B 13. Are you a model? 你是模特吗? Teacher:Patrick Key: 单词回顾、词性后缀

    因为这节课本身内容过于So easy~ Patrick给我补充了很多课外内容 课上内容(Lesson) I doesn't work  2层意思 1) 东西坏了,这个东西不能正常工作了.比如钟不走时间 ...

  7. numpy---one

    import numpy as np #创建数组(给array函数传递Python序列对象) a = np.array([1,2,3,4,5]) b = np.array((1,2,3,4,5,6)) ...

  8. ireport表单制作

    关于ireport的表单制作,可参考http://blog.csdn.net/wlwlwlwl015/article/details/51312853 这里主要讲解下如何在表单中加入table,如何让 ...

  9. Notes for GGplot2: Getting started with ggplot2

    Alpha-ma 2016/10/7 1 Introduction of GGplot2 ggplot2 is an R package for producing statistical, or d ...

  10. python零碎知识点

    0.规范化 使用Ctrl+Alt+L可以将代码排列格式更加规范化 1.浮点数 1.23x109就是1.23e9或者12.3e8:0.000012可以写成1.2e-5 2.字符串 >>> ...