From 00fbd7c4c7fc1cf70be3b7e394a194aab6a629b7 Mon Sep 17 00:00:00 2001 From: "steve.gao" Date: Wed, 12 Feb 2025 11:09:22 +0800 Subject: [PATCH] =?UTF-8?q?init=EF=BC=9Adrssionpage=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..79470b9 --- /dev/null +++ b/main.py @@ -0,0 +1,60 @@ +# 导入 +from DrissionPage import Chromium, ChromiumOptions + +# 连接浏览器 +# browser = Chromium() +# 获取标签页对象 +# tab = browser.latest_tab +# 访问网页 +# tab.get('https://etax.chinatax.gov.cn') + + +def inner_page(page): + """ + + """ + a_tab = page.ele('xpath:/html/body/div[4]/div/div/div[3]/ul/li[3]/a') # 缴税记录 + a_tab.click() + table_list = page.eles('xpath:/html/body/div[4]/div/div/div[3]/div[3]/div/div/div/div[2]/div/table/tbody/tr') # 凭证 + for tr in table_list: + href = tr.ele('@tag()=a') # 跳转链接 证明pdf 需要下载 + href.click() # 跳转下载 + tab.wait.doc_loaded() # 等待文档加载完毕 + page.get_screenshot(path='tmp', name='pic.jpg', full_page=False) # 下载发票 + break + +co = ChromiumOptions() +co.set_argument("--remote-debugging-port", "9222") +browser = Chromium(co) # 创建浏览器对象 +browser.set.retry_times(10) # 设置整体运行参数 +tab = browser.latest_tab # 获取Tab对象 +tab.get("https://etax.chinatax.gov.cn") +# #app > div.header-user > div > div.navbar-container > ul > li:nth-child(3) > a +# #app > div.header-user > div > div.navbar-container > ul > li.active > a +# ele = tab.ele("#app > div.header-user > div > div.navbar-container > ul > li:nth-child(3) > a") +try: + ele = tab.ele('xpath://*[@id="app"]/div[1]/div/div[2]/ul/li[3]/a') # 我要查询 + ele.click() + tab.ele('xpath://*[@id="app"]/div[2]/div/div/div[1]/div[2]/a[1]').click() # 申报查询 + + text = tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[2]/div[1]/div[1]').text # 待缴税款 + print(text) + text1 = tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[2]/div[1]/div[2]').text # 可申请退税金额 + print(text1) + ele = tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[1]/label[2]/span') # 已完成标签 + ele.click() + + table_list = tab.eles('xpath://*[@id="app"]/div[2]/div/div[2]/div[3]/div/div[3]/table/tbody/tr') + # for tr in table_list: + # # td = tab.eles('@tag:td') + # print(tr.texts()) # 获取所有的文本 + # # //*[@id="app"]/div[2]/div/div[2]/div[3]/div/div[3]/table/tbody/tr[2]/td[6]/div/a[1] + # href = tr.ele('@tag()=a') # 跳转链接 + # href.click() + # inner_page(tab) + # break +except Exception as e: + print(f"e is => {e}") + browser.quit() # 关闭浏览器 + +browser.quit() # 关闭浏览器