def request_detail(): """请求详情数据""" session = requests.Session() session.headers.update({ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36", }) url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "029bb843-b458-4d1c-8928-fe80da403cfe", # TODO 太多人测试此DocID,如果报错请更换DocID进行测试 } response = session.get(url, params=params) text = response.content.decode() if "请开启JavaScript并刷新该页" in text: # 如果有当前请求的url,尽量把url传进去,会更快一些 redirect_url = wzws_decrypt(text, url=response.url) # 没有url就算了 # redirect_url = wzws_decrypt(text) response = session.get(redirect_url) group_dict = parse_detail(response.text) pprint(group_dict)
def get_data(s): error_msg = "请开启JavaScript并刷新该页" url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": s, } #time.sleep(2) response = session.get(url, params=params, proxies=random.choice(proxy_list)) text = response.content.decode() if error_msg in text: retry = 3 for _ in range(retry): redirect_url = decrypt_wzws(text) response = session.get(redirect_url) text = response.content.decode() if error_msg not in text: break else: print("连续{}次获取数据失败".format(retry)) group_dict = parse_detail(response.text) #pprint(group_dict) return group_dict
def get_data(s): global first_time_out, second_time_out error_msg = "window.location.href=" url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": s, } time.sleep(delay_time) response = session.get(url, params=params, proxies=random.choice(ip_list), timeout=first_time_out) text = response.content.decode() if error_msg in text: retry = 3 for _ in range(retry): response = session.get(url, params=params, proxies=random.choice(ip_list), timeout=second_time_out) text = response.content.decode() if error_msg not in text: break else: if verbose: print("连续{}次获取数据失败".format(retry)) group_dict = parse_detail(response.text) #pprint(group_dict) return group_dict
def test_request_process(self): vjkl5 = Vjkl5() self.session.cookies["vjkl5"] = vjkl5 url = "http://wenshu.court.gov.cn/List/ListContent" data = { "Param": "案件类型:执行案件", "Index": 1, "Page": 10, "Order": "法院层级", "Direction": "asc", "vl5x": Vl5x(vjkl5), "number": Number(), "guid": Guid(), } response = self.session.post(url, data=data) json_data = json.loads(response.json()) print("列表数据:", json_data) run_eval = json_data.pop(0)["RunEval"] try: key = parse_run_eval(run_eval) except ValueError as e: raise ValueError("返回脏数据") from e else: print("RunEval解析完成:", key, "\n") key = key.encode() for item in json_data: cipher_text = item["文书ID"] print("解密:", cipher_text) plain_text = decrypt_doc_id(doc_id=cipher_text, key=key) print("成功, 文书ID:", plain_text, "\n") # 请求详情页 detail_url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": decrypt_doc_id(doc_id=json_data[0]["文书ID"], key=key), } response = self.session.get(detail_url, params=params) text = response.content.decode() if self.error_msg in text: redirect_url1 = wzws_decrypt(text, url=response.url) redirect_url2 = wzws_decrypt(text) self.assertEqual(redirect_url1, redirect_url2) response = self.session.get(redirect_url1) self.assertNotIn(self.error_msg, response.content.decode()) group_dict = parse_detail(response.text) pprint(group_dict)
def test_detail_parse(self): url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "13d4c01a-0734-4ec1-bbac-658f8bb8ec62", } response = self.session.get(url, params=params) if "请开启JavaScript并刷新该页".encode() in response.content: redirect_url = wzws_cid_decrypt(response.content) response = self.session.get(redirect_url) self.assertNotIn("请开启JavaScript并刷新该页", response.content.decode()) group_dict = parse_detail(response.text) pprint(group_dict)
def test_detail_parse(self): url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "a8b745f3-43ac-402c-99bf-68b9a9cae635", } response = self.session.get(url, params=params) text = response.content.decode() if self.error_msg in text: redirect_url = wzws_decrypt(text) response = self.session.get(redirect_url) self.assertNotIn(self.error_msg, response.content.decode()) group_dict = parse_detail(response.text) pprint(group_dict)
def test_detail_parse(self): url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "2e509686-62f9-4cf8-beeb-a7fe00ebcb05", } response = self.session.get(url, params=params) text = response.content.decode() if self.error_msg in text: redirect_url = wzws_decrypt(text) response = self.session.get(redirect_url) self.assertNotIn(self.error_msg, response.content.decode()) group_dict = parse_detail(response.text) pprint(group_dict)
def detail_page(self): """文书详情页""" url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "029bb843-b458-4d1c-8928-fe80da403cfe", } response = self.session.get(url, params=params) # 请求1 text = response.content.decode() if "请开启JavaScript并刷新该页" in text: # 如果使用代理,确保请求1和请求2的ip为同一个,否则将继续返回"请开启JavaScript并刷新该页" redirect_url = decrypt_wzws(text) response = self.session.get(redirect_url) # 请求2 group_dict = parse_detail(response.text) pprint(group_dict)
def test_detail_parse(self): url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "13d4c01a-0734-4ec1-bbac-658f8bb8ec62", } response = self.session.get(url, params=params) text = response.content.decode() if self.error_msg in text: redirect_url = wzws_decrypt(text) response = self.session.get(redirect_url) self.assertNotIn(self.error_msg, response.content.decode()) group_dict = parse_detail(response.text) pprint(group_dict)
def request_detail(): """请求详情数据""" session = requests.Session() session.headers.update({ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36", }) url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "13d4c01a-0734-4ec1-bbac-658f8bb8ec62", } response = session.get(url, params=params) if "请开启JavaScript并刷新该页".encode() in response.content: redirect_url = wzws_cid_decrypt(response.content) response = session.get(redirect_url) group_dict = parse_detail(response.text) pprint(group_dict)
def test_detail_page(self): url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx" params = { "DocID": "a8b745f3-43ac-402c-99bf-68b9a9cae635", } response = self.session.get(url, params=params) text = response.content.decode() if self.error_msg in text: retry = 3 for _ in range(retry): redirect_url = decrypt_wzws(text) response = self.session.get(redirect_url) text = response.content.decode() if self.error_msg not in text: break else: self.fail("连续{}次获取数据失败".format(retry)) group_dict = parse_detail(response.text) pprint(group_dict)