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