def getPhoneLocatin(): match=re.compile(ur".*?province:'(.*?)'.*") temp=[] for phone in loadData(): realphone=phone if len(str(phone).strip())>11: phone=str(phone).strip()[:11] try: from requests.packages.urllib3.exceptions import InsecureRequestWarning # 禁用安全请求警告 requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
#verify=False禁用证书 response=requests.get(url='http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=%s'%phone,verify=False) search=match.search(response.content.decode('gbk')) location='' if search: location=search.group(1) temp.append((realphone,location)) if len(temp)>=5000: cursor.executemany(sql,temp) print '..' conn.commit() temp=[] except Exception as e: pass
本文介绍了一种通过网络请求批量获取手机号码对应地理位置信息的方法。利用正则表达式解析响应内容并提取省份信息,同时展示了如何处理请求过程中的异常情况。
1444

被折叠的 条评论
为什么被折叠?



