1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #!/usr/bin/env python
- # coding:utf-8
- import requests,json,time
- import random,string
- from setting import proxies
- from urllib import parse
- from lxml import etree
- from pymongo import MongoClient
- from a_cfg_dg_zsq import tail_call_optimized
- myclients = MongoClient("mongodb://127.0.0.1:27017/")
- myco_jb1 = myclients['shuiwu_ml']['xinjiang']
- import urllib3
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
- from mongo_cho import myco30
- r = requests.session()
- r.keep_alive = False
- def retry(times, exceptions=None):
- exceptions = exceptions if exceptions is not None else Exception
- def wrapper(func):
- def wrapper(*args, **kwargs):
- last_exception = None
- for _ in range(times):
- try:
- return func(*args, **kwargs)
- except exceptions as e:
- last_exception = e
- raise last_exception
- return wrapper
- return wrapper
- @tail_call_optimized
- @retry(3)
- def r1(name):
- etm = int(time.time() * 1000)
- url = 'https://etax.xinjiang.chinatax.gov.cn/yhs-web/api/yhsyzm/get?{}'.format(etm)
- headers = {
- "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36",
- }
- response = r.get(url=url,headers=headers,proxies=proxies,verify=False)
- time.sleep(1)
- num = string.ascii_letters + string.digits
- yzm = "".join(random.sample(num, 4))
- # code_img = response.content
- # with open('{}.png'.format('1'), 'wb') as fp:
- # fp.write(code_img)
- # print(code_img)
- # a = input()
- # print(a)
- data = {
- "yzm":yzm,
- "nsrmc": name,
- "pageSize": 10,
- "sswfrlx": "00",
- "pageIndex": 1
- }
- url1 = 'https://etax.xinjiang.chinatax.gov.cn/yhs-web/api/zdwfaj/ajlbcx'
- response1 = r.post(url=url1,headers=headers,json=data,proxies=proxies,verify=False)
- print(response1.json())
- # print(response1.text)
- rsd = response1.json()
- rst = rsd['value']['result']
- list1 = []
- for i in rst:
- pid = i['id']
- etm1 = int(time.time() * 1000)
- params = {
- "id":pid,
- "sswfrlx": "00",
- "timestamp": etm1,
- }
- url2 = 'https://etax.xinjiang.chinatax.gov.cn/yhs-web/api/zdwfaj/ajmxcx'
- response2= r.get(url=url2,headers=headers,params=params,proxies=proxies,verify=False)
- rsd1 = response2.json()
- rsd2 = rsd1['value']
- list1.append(rsd2)
- # print(response2.text)
- time.sleep(1)
- print(list1)
- if list1:
- myco30.insert_many(list1)
- # r1(name)
- def runs():
- a = myco_jb1.find().skip(275171+34665+4542)
- num = 0
- for i in a:
- num +=1
- name = i['name']
- print(num,name )
- r1(name)
- runs()
|