python 获取gearbest地址库代码
import requests
import json # 用来去掉多余的字符,并格式化
def geshihua(str):
s = None
if "/**/_get_country(" in str:
m = str.index('/**/_get_country(')+17
s = str[m:-2]
elif '/**/_user_get_province' in str:
m = str.index('/**/_user_get_province') + 23
s = str[m:-2]
elif '/**/_user_get_city' in str:
m = str.index('/**/_user_get_city') + 19
s = str[m:-2]
s = json.loads(s)
s = s['data']
return s def country():
requests.packages.urllib3.disable_warnings()
user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
headers = {'User-Agent': user_agent}
url = "https://www.gearbest.com/get-country?callback=_get_country"
response = requests.get(url,headers)
countrys = response.content.decode()
countrys = geshihua(countrys)
return countrys def province(countryCode):
requests.packages.urllib3.disable_warnings()
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
headers = {'User-Agent': user_agent}
url = "https://www.gearbest.com/user/get-province?callback=_user_get_province&countryCode=" + countryCode
response = requests.get(url, headers)
provinces = response.content.decode()
provinces = geshihua(provinces)
return provinces def city(provinceCode):
requests.packages.urllib3.disable_warnings()
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
headers = {'User-Agent': user_agent}
url = "https://user.gearbest.com/user/get-city?callback=_user_get_city&provinceCode=" + str(provinceCode)
response = requests.get(url, headers)
citys = response.content.decode()
citys = geshihua(citys)
return citys def main():
f = open('address.txt', 'a') countrys = country()
for c in countrys:
countryName = c['countryName']
# print(countryName)
provinces = province(c['countryCode'])
for p in provinces:
provinceName = p['provinceName']
# print(p['provinceCode'])
citys = city(p['cdpId'])
# print(citys)
if len(citys) != 0 :
for t in citys:
cityName = t['cityName']
f.write(countryName + ',' + provinceName + ',' + cityName + '\n')
print(countryName + ',' + provinceName + ',' + cityName)
else:
f.write(countryName + ',' + provinceName + ',None' + '\n')
print(countryName + ',' + provinceName + ',None')
f.close() if __name__=="__main__":
main()
python 获取gearbest地址库代码的更多相关文章
- python 获取 mac 地址 的代码
python 获取 mac 地址 的例子,有需要的朋友可以参考下. #!/bin/python import os import re def GetMac(): if os.name == ...
- python获取内存地址上存储的值
在python中,可以通过id()这个方法来获取对象的内存地址. 但是反过来,怎么获取内存地址上存储的值? 先看一段代码: from ctypes import string_at from sys ...
- Linux下Python获取IP地址
<lnmp一键安装包>中需要获取ip地址,有2种情况:如果服务器只有私网地址没有公网地址,这个时候获取的IP(即私网地址)不能用来判断服务器的位置,于是取其网关地址用来判断服务器在国内还是 ...
- python 获取mac地址zz
通过python获取当前mac地址的方法如下:(1)通用方法,借助uuid模块def get_mac_address(): import uuid node = uuid.getnode() ...
- python获取ip地址
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import socket,fcntl,struct #crontab下shell命令无 ...
- Python 获取 网卡 MAC 地址
/*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...
- ios开发 iphone中获取网卡地址和ip地址
这是获取网卡的硬件地址的代码,如果无法编译通过,记得把下面的这几个头文件加上把. #include <sys/socket.h> // Per msqr#include <sys/s ...
- iOS 获取IP地址
一.获取本机IP地址 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #import <ifadd ...
- python获取文件路径
摘自:https://blog.csdn.net/Poo_Chai/article/details/89764001 import os root_path = os.path.abspath(os. ...
随机推荐
- SQL Server Replication的分发服务器的快照文件夹位置查找
SQL Server分发服务器配置中,需要配置快照文件夹(Snapshot Folder),用于存储发布的数据和架构文件的工作目录,那么如何查找当前SQL Server数据库服务器的分发服务器的快照文 ...
- web前端(1)——了解什么是前端,以及与后端的关系
简介 1.什么是web前端 说这个之前,我们先了解web前端工程师是干什么的,百度百科的解释: Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript/Flash等各种Web ...
- emacs 配置.emacs
emacs 配置.emacs (require 'package) (package-initialize) (add-to-list'package-archives '("melpa&q ...
- Linux 小知识翻译 - 「LDAP」
这次聊聊「LDAP」. LDAP是「Lightweight Directory Access Protocol」的所有,从名字上可以看出是协议的一种. LDAP是访问数据库(层次型数据库)的组件.管理 ...
- Python爬虫-05:Ajax加载的动态页面内容
1. 获取AJAX加载动态页面的内容 1.1. Introduction 如果所爬取的网址是通过Ajax方式加载的,就直接抓包,拿他后面传输数据的文件 有些网页内容使用AJAX加载,只要记得,AJAX ...
- [福大软工] Z班 团队Alpha阶段成绩汇总
团队成绩汇总表 团队 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 总分 Dipper 9 85 90 26 42 27.5 120 74 25 111 19 628.5 SW ...
- python3编写网络爬虫23-分布式爬虫
一.分布式爬虫 前面我们了解Scrapy爬虫框架的基本用法 这些框架都是在同一台主机运行的 爬取效率有限 如果多台主机协同爬取 爬取效率必然成倍增长这就是分布式爬虫的优势 1. 分布式爬虫基本原理 1 ...
- Maven——settings.xml配置
settings.xml配置 原文 <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed ...
- 14.UA池和代理池
今日概要 scrapy下载中间件 UA池 代理池 今日详情 一.下载中间件 先祭出框架图: 下载中间件(Downloader Middlewares) 位于scrapy引擎和下载器之间的一层组件. - ...
- 精度 Precision
柏拉图认为,尽管世间万物是不完美的,但存在一种永恒不变的形式,这个形式是完美的,而生命的意义就是让这个世界尽可能的接近这个完美的形式. 怎么理解这句话,和我们今天讲的精度有什么关系.我们先举一个例子, ...