Python抓取淘宝IP地址数据
def fetch(ip):
url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' + ip
result = []
try:
response = urllib.urlopen(url).read()
jsondata = json.loads(response)
if jsondata[u'code'] == 0:
result.append(jsondata[u'data'][u'ip'].encode('utf-8'))
result.append(jsondata[u'data'][u'country'].encode('utf-8'))
result.append(jsondata[u'data'][u'country_id'].encode('utf-8'))
result.append(jsondata[u'data'][u'area'].encode('utf-8'))
result.append(jsondata[u'data'][u'area_id'].encode('utf-8'))
result.append(jsondata[u'data'][u'region'].encode('utf-8'))
result.append(jsondata[u'data'][u'region_id'].encode('utf-8'))
result.append(jsondata[u'data'][u'city'].encode('utf-8'))
result.append(jsondata[u'data'][u'city_id'].encode('utf-8'))
result.append(jsondata[u'data'][u'county'].encode('utf-8'))
result.append(jsondata[u'data'][u'county_id'].encode('utf-8'))
result.append(jsondata[u'data'][u'isp'].encode('utf-8'))
result.append(jsondata[u'data'][u'isp_id'].encode('utf-8'))
else:
return 0, result
except:
logging.exception("Url open failed:" + url)
return 0, result
return 1, result def worker(ratelimit, jobs, results, progress):
global cancel
while not cancel:
try:
ratelimit.ratecontrol()
ip = jobs.get(timeout=2) # Wait 2 seconds
ok, result = fetch(ip)
if not ok:
logging.error("Fetch information failed, ip:{}".format(ip))
progress.put("") # Notify the progress even it failed
elif result is not None:
results.put(" ".join(result))
jobs.task_done() # Notify one item
except Queue.Empty:
pass
except:
logging.exception("Unknown Error!")
def process(target, results, progress):
global cancel
while not cancel:
try:
line = results.get(timeout=5)
except Queue.Empty:
pass
else:
print >>target, line
progress.put("")
results.task_done()
def progproc(progressbar, count, progress):
"""
Since ProgressBar is not a thread-safe class, we use a Queue to do the counting job, like
two other threads. Use this thread do the printing of progress bar. By the way, it will
print to stderr, which does not conflict with the default result output(stdout).
"""
idx = 1
while True:
try:
progress.get(timeout=5)
except Queue.Empty:
pass
else:
progressbar.update(idx)
idx += 1
Python抓取淘宝IP地址数据的更多相关文章
- Python 爬取淘宝商品数据挖掘分析实战
Python 爬取淘宝商品数据挖掘分析实战 项目内容 本案例选择>> 商品类目:沙发: 数量:共100页 4400个商品: 筛选条件:天猫.销量从高到低.价格500元以上. 爬取淘宝商品 ...
- 简单的抓取淘宝关键字信息、图片的Python爬虫|Python3中级玩家:淘宝天猫商品搜索爬虫自动化工具(第一篇)
Python3中级玩家:淘宝天猫商品搜索爬虫自动化工具(第一篇) 淘宝改字段,Bugfix,查看https://github.com/hunterhug/taobaoscrapy.git 由于Gith ...
- python(27) 抓取淘宝买家秀
selenium 是Web应用测试工具,可以利用selenium和python,以及chromedriver等工具实现一些动态加密网站的抓取.本文利用这些工具抓取淘宝内衣评价买家秀图片. 准备工作 下 ...
- 一次Python爬虫的修改,抓取淘宝MM照片
这篇文章是2016-3-2写的,时隔一年了,淘宝的验证机制也有了改变.代码不一定有效,保留着作为一种代码学习. 崔大哥这有篇>>小白爬虫第一弹之抓取妹子图 不失为学python爬虫的绝佳教 ...
- Python爬虫实战四之抓取淘宝MM照片
原文:Python爬虫实战四之抓取淘宝MM照片其实还有好多,大家可以看 Python爬虫学习系列教程 福利啊福利,本次为大家带来的项目是抓取淘宝MM照片并保存起来,大家有没有很激动呢? 本篇目标 1. ...
- Python爬虫实战八之利用Selenium抓取淘宝匿名旺旺
更新 其实本文的初衷是为了获取淘宝的非匿名旺旺,在淘宝详情页的最下方有相关评论,含有非匿名旺旺号,快一年了淘宝都没有修复这个. 可就在今天,淘宝把所有的账号设置成了匿名显示,SO,获取非匿名旺旺号已经 ...
- Python爬虫之一 PySpider 抓取淘宝MM的个人信息和图片
ySpider 是一个非常方便并且功能强大的爬虫框架,支持多线程爬取.JS动态解析,提供了可操作界面.出错重试.定时爬取等等的功能,使用非常人性化. 本篇通过做一个PySpider 项目,来理解 Py ...
- 甜咸粽子党大战,Python爬取淘宝上的粽子数据并进行分析
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 爬虫 爬取淘宝数据,本次采用的方法是:Selenium控制Chrome浏览 ...
- 芝麻HTTP:Python爬虫实战之抓取淘宝MM照片
本篇目标 1.抓取淘宝MM的姓名,头像,年龄 2.抓取每一个MM的资料简介以及写真图片 3.把每一个MM的写真图片按照文件夹保存到本地 4.熟悉文件保存的过程 1.URL的格式 在这里我们用到的URL ...
随机推荐
- 强大的字符串格式化函数 - format
自python2.6开始,新增了一种格式化字符串的函数str.format(),它通过{}和:来代替% 位置方法格式化 >>>'{}-{}'.format('simon','ting ...
- tp中调用PHP系统扩展类
例如使用Redis扩展类: use Reids; $redis = new Redis();
- Ubuntu 13.10 PHP 5.5.x mcrypt missing – Fatal Error: Undefined function mcrypt_encrypt()!
[原文]http://www.tuicool.com/articles/goto?id=myM7veR I had updgraded my Ubuntu from 13.04 to 13.10 la ...
- Poco之ftp获取文件列表以及下载文件
#include <iostream>#include <string>#include <vector>#include <algorithm>#in ...
- leetcode第四题:Median of Two Sorted Arrays (java)
Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find t ...
- JavaScript自学代码--(三)
//通过 id 查找 HTML 元素 var x = document.getElementById("demo"); //通过标签名查找 HTML 元素 //本例查找 id=&q ...
- CPU,MPU,MCU,SOC,SOPC联系与差别
转自CPU,MPU,MCU,SOC,SOPC联系与差别 1.CPU(Central Processing Unit),是一台计算机的运算核心和控制核心.CPU由运算器.控制器和寄存器及实现它们之间联系 ...
- PCR理解
http://blog.csdn.net/niehanzi/article/details/4450154 PCR的物理意义: PCR存在于TS包的自适应域中,如下图: PCR用来同步前端编码器和后端 ...
- BroadCastReceiver中耗时操作导致ANR
現象:廣播接收器中進行耗時的I/O操作導致ANR. 查資料發現每次广播到来时 , 会重新创建 BroadcastReceiver 对象 , 并且调用 onReceive() 方法 , 执行完以后 该对 ...
- 虚拟机安装了ubuntu,忘记密码修复
在虚拟机中按照以下步骤重新为用户设定新密码. 重启Ubuntu,随即长按shift进入grub菜单: 选择recovery mode,回车确认: 在Recovery Menu中,选择“Root Dro ...