Python如何抓取淘宝IP地址数据
发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,这篇文章主要介绍Python如何抓取淘宝IP地址数据,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!示例代码def fetch(ip): url = 'http://ip.
千家信息网最后更新 2025年02月03日Python如何抓取淘宝IP地址数据
这篇文章主要介绍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地址数据"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
地址
数据
淘宝
内容
篇文章
代码
价值
兴趣
小伙
小伙伴
更多
知识
示例
行业
资讯
资讯频道
频道
参考
帮助
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
和平精英充值服务器有用吗
武邑软件开发文档在线咨询
日本软件开发考试gait
网络服务器安全配置
数据库 显示表
数据库连接无法获得
太空狼人杀为什么服务器老是中断
乳山安卓软件开发
九义网络技术有限公司
艾克斯特capp服务器安装
山西网络服务器机箱是什么物理机
软件开发收入入什么科目
无锡好一点的软件开发公司
奥迪斯电梯服务器操作使用说明
数据库 主从同步
以网络安全为主题的大字
该怎么打开数据库的共享文件
信息网络安全等保
数据库删除语句有哪些方法
服务器虚拟光驱
导致内部网络安全的主因
日本软件开发考试gait
茄子网络安全手抄报
超低功耗 linux服务器
国企的软件开发往哪跳
数据库分级安全管理
mac电脑增加服务器快捷方式
微机数据库数电
网警保障网络安全的口号
湖北枣阳软件开发