123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import json
- import re
- import time
- from RS import Get_Cookie
- from Captcha import Init_Captcha
- import ddddocr
- class Get_Info:
- def __init__(self):
- self.headers = {
- "Connection": "keep-alive",
- "Pragma": "no-cache",
- "Cache-Control": "no-cache",
- "Accept": "application/json, text/javascript, */*; q=0.01",
- "X-Requested-With": "XMLHttpRequest",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
- "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
- "Origin": "http://zxgk.court.gov.cn",
- "Referer": "http://zxgk.court.gov.cn/xgl/",
- "Accept-Language": "zh-CN,zh;q=0.9"
- }
- self.Get_Cookie = Get_Cookie()
- self.session, self.ctx200 = self.Get_Cookie.main()
- self.updateCookie = self.Get_Cookie.update_cookie
- self.initURL = "http://zxgk.court.gov.cn/xgl"
- self.ListURL = "http://zxgk.court.gov.cn/xgl/searchXgl.do"
- self.ocr = ddddocr.DdddOcr()
- self.totalPage = 0
- self.pdfs = []
- self.file = open("xglLink.txt","w",encoding="utf-8")
- def init_page(self):
- init_page_response = self.session.get(url=self.initURL, headers=self.headers)
- print("init_page_response ===>", init_page_response)
- # print("init_page_response.text ===>",init_page_response.text)
- self.updateCookie()
- def init_captcha(self):
- self.CaptchaURL, self.captchaId, self.MyRandom = Init_Captcha().main()
- Captcha_headers = {
- "Connection": "keep-alive",
- "Pragma": "no-cache",
- "Cache-Control": "no-cache",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
- "Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
- "Referer": "http://zxgk.court.gov.cn/xgl/",
- "Accept-Language": "zh-CN,zh;q=0.9"
- }
- CaptchaResponse = self.session.get(url=self.CaptchaURL,headers=Captcha_headers)
- print("请求验证码的响应结果 ===>",CaptchaResponse)
- with open("captcha.jpg", 'wb') as f:
- f.write(CaptchaResponse.content)
- with open("captcha.jpg", 'rb') as f:
- image = f.read()
- self.pCode = self.ocr.classification(image)
- print("验证码的结果 ===>",self.pCode)
- self.updateCookie()
- def check_Captcha(self):
- url = "checkyzm.do?captchaId=" + self.captchaId + "&pCode=" + self.pCode + ""
- checkURL = self.ctx200.call("check_yzm","GET",url,self.captchaId,self.pCode)
- checkURL = "http://zxgk.court.gov.cn" + checkURL
- print("验证码验证的URL ===>",checkURL)
- response = self.session.get(url=checkURL,headers=self.headers)
- self.updateCookie()
- if response.text.split("\n")[0] == "1":
- print("验证码验证通过")
- return True
- else:
- print("验证码验证失败,退出程序")
- return False
- def check_yzm(self):
- while True:
- self.init_captcha()
- ret = self.check_Captcha()
- self.updateCookie()
- if ret == True:
- break
- else:
- print("验证失败,正在进行重新请求验证码并验证")
- print("验证码的验证通过")
- def Get_List(self, name, currentPage):
- List_data = {
- "pName": name,
- "pCardNum": "",
- "selectCourtId": "0",
- "pCode": self.pCode,
- "captchaId": self.captchaId,
- "searchCourtName": "全国法院(包含地方各级法院)",
- "selectCourtArrange": "1",
- "currentPage": currentPage
- }
- url = self.ctx200.call("get_list", "POST", "searchXgl.do")
- print("url ===>",url)
- url = "http://zxgk.court.gov.cn" + url
- ListResponse = self.session.post(url=url,headers=self.headers,data=List_data)
- print("列表页的响应 ===>",ListResponse.text)
- self.updateCookie()
- try:
- self.totalPage = re.findall(r'"totalPage":(.*?),"',ListResponse.text)[0]
- print("totalPage ===>",self.totalPage)
- self.pdfs.append(re.findall(r'"FILEPATH":"(.*?)","', ListResponse.text))
- return True
- except:
- print("获取totalPage失败了 ListResponse ===> ",ListResponse.text)
- self.check_yzm()
- return False
- def write_link(self):
- for pdf in self.pdfs:
- for i in pdf:
- self.file.write(i)
- self.file.write("\n")
- self.pdfs = []
- def main(self):
- self.init_page()
- self.check_yzm()
- i = 1
- while True:
- print("i =====>",i)
- if i == int(self.totalPage):
- break
- if self.Get_List("张三",i):
- i += 1
- self.write_link()
- print("关键字为 张三 的内容写入完毕")
- self.file.close()
- if __name__ == '__main__':
- Get_Info().main()
|