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元数据(二)
背景 上一篇中,我介绍了SQL Server 允许访问数据库的元数据,为什么有元数据,如何使用元数据.这一篇中我会介绍如何进一步找到各种有价值的信息.以触发器为例,因为它们往往一起很多问题. 那么如何 ...
- [Hive_10] Hive 的分析函数
0. 说明 Hive 的分析函数 窗口函数 | 排名函数 | 最大值 | 分层次 | lead && lag 统计活跃用户 | cume_dist 1. 窗口函数(开窗函数) ove ...
- 【算法】LeetCode算法题-Search Insert Position
这是悦乐书的第152次更新,第154篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第11题(顺位题号是35).给定排序数组和目标值,如果找到目标,则返回索引. 如果没有, ...
- 力扣算法题—069x的平方根
实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 示例 ...
- C. Ayoub and Lost Array cf dp
C. Ayoub and Lost Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 面试linux运维一定会问到Shell脚本这24个问题
面试linux运维一定会问到Shell脚本这24个问题 虽然现在Python在运维工作中已经使用很普遍,但是很多企业在找Linux云计算工程师的时候还是会问到 shell 脚本的问题,它有助于你在工作 ...
- 彻底理解js中的&&和||
阅读代码时对一行代码很困惑 step > max_step && (step = min_step); 查阅资料后发现它等价于 if (step > max_step) { ...
- UVA1374-Power Calculus(迭代加深搜索)
Problem UVA1374-Power Calculus Accept:323 Submit:2083 Time Limit: 3000 mSec Problem Description I ...
- Linux中的update和upgrade的区别
update是更新源里的软件列表 upgrade顾名思义是升级,升级你系统里的软件
- PHP 3种方法实现采集网站数据
什么叫采集? 就是使用PHP程序,把其他网站中的信息抓取到我们自己的数据库中.网站中. PHP制作采集的技术: 从底层的socket到高层的文件操作函数,一共有3种方法可以实现采集. 1. 使用soc ...