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 ...
随机推荐
- 【WPF】布局控件总结
<Canvas>:画布,默认不会自动裁减超出内容,即溢出的内容会显示在Canvas外面,这是因为默认 ClipToBounds="False":可设置ClipToBou ...
- 安卓手机无法连接VPN的解决办法
这篇不能算是技术博客吧,但是在网上很难找到解决方案,至少我找了好久也没弄好.. 三种方案,因机而异,我就长话短说了: 一. "/system/xbin" 和 "/syst ...
- HDU 1394 Minimum Inversion Number 线段树
题目: http://acm.hdu.edu.cn/showproblem.php?pid=1394 没看到多组输入,WA了一万次...... 其实很简单,有人暴力过得,我感觉归并排序.二叉排序树求逆 ...
- POJ 1860 Currency Exchange 毫无优化的bellman_ford跑了16Ms,spfa老是WA。。
题目链接: http://poj.org/problem?id=1860 找正环,找最长路,水题,WA了两天了.. #include <stdio.h> #include <stri ...
- ubuntu下SVN服务器安装配置
SVN服务器端: 1.安装包 $ sudo apt-get install subversion 2.添加svn管理用户及subversion组 $ sudo adduser svnuser $ su ...
- NET SqlClient
NET SqlClient的使用与常见问题 阅读目录 一.简介 二.使用ADO.NET 三.常见问题 回到目录 一.简介 在很多要求性能的项目中,我们都要使用传统的ADO.NET的方式来完成我们日常的 ...
- XSS与字符编码的那些事儿
目录 0x00:基本介绍 0x01:html实体编码 0x02:新增的实体编码 实体编码变异以及浏览器的某些工作原理! 0x03:javascript编码 0x04:base64编码 0x05:闲扯 ...
- ArrayList与Vector、HashMap与HashTable
摘自api: 1.ArrayList与Vector: 原文:This class(ArrayList) is roughly equivalent to Vector, except that it ...
- Python还是很重要的,不能丢。学习IF和WHILE
number = 23 guess = int(input('Enter an interger : ')) if guess == number: print('Congratulations, y ...
- 使用IRP进行文件操作
使用IRP进行文件操作 首先声明这个是菜鸟—我的学习日记,不是什么高深文章,高手们慎看. 一定要先感谢为技术的进步而付出辛勤汗水的人,感谢他们对技术的共享. 一个通用IRP访问文件的十六进制编辑器(开 ...