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 ...
随机推荐
- Couldn't get lock for %t/vertx.log
今天在启动vertx框架的项目时,报“Couldn't get lock for %t/vertx.log”的错误. 解决方案: 1,找出vertx.log的目录.一般在(C:\Users\Admin ...
- php提取背景图片
preg_match_all('/background\s*-\s*+image\s*:\s*url\s*\("*([^"]*)"*\)/i', $content,$ma ...
- TDirectory.GetCreationTime、TDirectory.SetCreationTime获取和设置文件夹创建时间
使用函数: System.IOUtils.TDirectory.GetCreationTime//获取创建时间 System.IOUtils.TDirectory.SetCreationTime//设 ...
- .Net平台下的B/S开发框架
一.前言 本文主要是对.Net平台下的几种B/S开发框架进行比较.只对比前端展现和界面业务逻辑的部分,对于后台的数据层.业务层.持久层等则不作讨论,因为这些部分是完全可以共用的. 主要从如下几个维度 ...
- iOS开发 - NSBundle, NSDevice, NSLocale
iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发api可以获取到 ...
- Android Camera 预览图像被拉伸变形的解决方法【转】
问题描述: 预览图像被拉伸变形 问题原因: 由于预览图像大小跟SurfaceView 大小不一致引起 解决方法: 获取系统支持的所有预览尺寸[getSupportedPictureSizes],然后再 ...
- CSS中IE8和chrom像素百分比计算差异
IE8中和chrome在计算像素百分比上,IE8舍一位取元素像素大小,chrome则使用四舍五入取元素像素大小: 比如:<body><div stype=“width:30%”> ...
- HIVE编程指南之HiveQL的学习笔记1
// HiveQLa) 数据定义语言1 数据库表的一个目录或命名空间,如果用户没有指定数据库的话,那么将会使用默认的数据库default-----创建数据库CREATE DATABASE guoyon ...
- Introduction to Gaussian Processes
Introduction to Gaussian Processes Gaussian processes (GP) are a cornerstone of modern machine learn ...
- 降维(一)----说说主成分分析(PCA)的源头
降维(一)----说说主成分分析(PCA)的源头 降维系列: 降维(一)----说说主成分分析(PCA)的源头 降维(二)----Laplacian Eigenmaps --------------- ...