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")
def test_list(self): response = self.session.get("http://wenshu.court.gov.cn/list/list/") 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) _ = self.session.get(redirect_url1) url = "http://wenshu.court.gov.cn/List/ListContent" data = { "Param": "案件类型:行政案件", "Index": 1, "Page": 10, "Order": "法院层级", "Direction": "asc", "vl5x": Vl5x(self.session.cookies["vjkl5"]), "number": Number(), "guid": Guid(), } response = self.session.post(url, data=data) self.assertNotIn(self.error_msg, response.content.decode()) print(response.text)
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_vl5x(self): online_test_data = [] for data in local_test_data: vjkl5 = data["vjkl5"] vl5x = data["vl5x"] py_vl5x = Vl5x(vjkl5) self.assertEqual(py_vl5x, vl5x, "vl5x不一致") online_test_data.append({ "vjkl5": vjkl5, "vl5x": py_vl5x, }) print("vl5x本地测试通过, 如需在线测试vl5x请复制以下js到文书网列表页console中测试:\n{}".format( online_test_js % online_test_data))
def test_list_page(self): url = "http://wenshu.court.gov.cn/List/ListContent" data = { "Param": "案件类型:执行案件", "Index": 1, "Page": 10, "Order": "法院层级", "Direction": "asc", "vl5x": Vl5x(self.session.cookies.setdefault("vjkl5", Vjkl5())), "number": Number(), "guid": Guid(), } response = self.session.post(url, data=data) text = response.content.decode() if self.error_msg in text: retry = 3 for _ in range(retry): redirect_url = decrypt_wzws(text) response = self.session.post(redirect_url, data=data) text = response.content.decode() if self.error_msg not in text: break else: self.fail("连续{}次获取数据失败".format(retry)) json_data = json.loads(response.json()) print("列表数据:", json_data) run_eval = json_data.pop(0)["RunEval"] try: key = decrypt_runeval(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")
def request_list(): """请求列表数据""" 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", "X-Requested-With": "XMLHttpRequest", }) vjkl5 = Vjkl5() session.cookies["vjkl5"] = vjkl5 list_url = "http://wenshu.court.gov.cn/List/ListContent" data = { "Param": "案件类型:刑事案件", # TODO 太多人测试此检索条件的数据,如果报错或返回脏数据请更换别的检索条件进行测试 "Index": 1, "Page": 10, "Order": "法院层级", "Direction": "asc", "vl5x": Vl5x(vjkl5), "number": Number(), "guid": Guid(), } response = session.post(list_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")
def test_list(self): response = self.session.get("http://wenshu.court.gov.cn/list/list/") if "请开启JavaScript并刷新该页".encode() in response.content: redirect_url = wzws_cid_decrypt(response.content) _ = self.session.get(redirect_url) url = "http://wenshu.court.gov.cn/List/ListContent" data = { "Param": "关键词:合同", "Index": 1, "Page": 10, "Order": "法院层级", "Direction": "asc", "vl5x": Vl5x(self.session.cookies["vjkl5"]), "number": Number(), "guid": Guid(), } response = self.session.post(url, data=data) self.assertNotIn("请开启JavaScript并刷新该页", response.content.decode()) print(response.text)
def list_page(self): """文书列表页""" url = "http://wenshu.court.gov.cn/List/ListContent" data = { "Param": "案件类型:刑事案件", "Index": 1, "Page": 10, "Order": "法院层级", "Direction": "asc", "vl5x": Vl5x(self.session.cookies.setdefault("vjkl5", Vjkl5())), "number": Number(), "guid": Guid(), } response = self.session.post(url, data=data) # 请求1 text = response.content.decode() if "请开启JavaScript并刷新该页" in text: # 如果使用代理,确保请求1和请求2的ip为同一个,否则将继续返回"请开启JavaScript并刷新该页" redirect_url = decrypt_wzws(text) response = self.session.post(redirect_url, data=data) # 请求2 json_data = json.loads(response.json()) print("列表数据:", json_data) run_eval = json_data.pop(0)["RunEval"] try: key = decrypt_runeval(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")