千家信息网

Python如何抓取淘宝IP地址数据

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要介绍Python如何抓取淘宝IP地址数据,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!示例代码def fetch(ip): url = 'http://ip.
千家信息网最后更新 2026年11月02日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安全错误 数据库的锁怎样保障安全 互联网科技 广东猪兼强互联网科技有限公司 金融科技创新监管互联网金融 华宇互联网科技 互联网与未来科技 电子科技大学互联网 科技互联网公司logo 掌上梦互联网科技 互联网科技博客 人人互联网科技是培训 太原新华互联网科技学校怎么样 互联网科技博主是什么意思 互联网和黑科技的看法 崇明区互联网教育科技售后服务 华夏恒生科技与互联网科技 伍佰万互联网科技怎么赚钱 21世纪互联网科技成就 陕西云淼互联网科技公司 保山浩联互联网科技有限公司 承德科技产业互联网平台 华宇互联网科技 科技互联网公司logo 居家互联网科技有限公司 互联网科技类展会 顺网科技2021年互联网排名 互联网和高科技公司 米聚互联网科技南京有限公司排面 山东子淼互联网科技有限公司 南京一网一红互联网科技有限公司 九思连强互联网电子科技有限公司
0