drssionPage demo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.4 KiB

  1. # 导入
  2. from DrissionPage import Chromium, ChromiumOptions
  3. # 连接浏览器
  4. # browser = Chromium()
  5. # 获取标签页对象
  6. # tab = browser.latest_tab
  7. # 访问网页
  8. # tab.get('https://etax.chinatax.gov.cn')
  9. def inner_page(page):
  10. """
  11. """
  12. a_tab = page.ele('xpath:/html/body/div[4]/div/div/div[3]/ul/li[3]/a') # 缴税记录
  13. a_tab.click()
  14. table_list = page.eles('xpath:/html/body/div[4]/div/div/div[3]/div[3]/div/div/div/div[2]/div/table/tbody/tr') # 凭证
  15. for tr in table_list:
  16. href = tr.ele('@tag()=a') # 跳转链接 证明pdf 需要下载
  17. href.click() # 跳转下载
  18. tab.wait.doc_loaded() # 等待文档加载完毕
  19. page.get_screenshot(path='tmp', name='pic.jpg', full_page=False) # 下载发票
  20. break
  21. co = ChromiumOptions()
  22. co.set_argument("--remote-debugging-port", "9222")
  23. browser = Chromium(co) # 创建浏览器对象
  24. browser.set.retry_times(10) # 设置整体运行参数
  25. tab = browser.latest_tab # 获取Tab对象
  26. tab.get("https://etax.chinatax.gov.cn")
  27. # #app > div.header-user > div > div.navbar-container > ul > li:nth-child(3) > a
  28. # #app > div.header-user > div > div.navbar-container > ul > li.active > a
  29. # ele = tab.ele("#app > div.header-user > div > div.navbar-container > ul > li:nth-child(3) > a")
  30. try:
  31. ele = tab.ele('xpath://*[@id="app"]/div[1]/div/div[2]/ul/li[3]/a') # 我要查询
  32. ele.click()
  33. tab.ele('xpath://*[@id="app"]/div[2]/div/div/div[1]/div[2]/a[1]').click() # 申报查询
  34. text = tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[2]/div[1]/div[1]').text # 待缴税款
  35. print(text)
  36. text1 = tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[2]/div[1]/div[2]').text # 可申请退税金额
  37. print(text1)
  38. ele = tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[1]/label[2]/span') # 已完成标签
  39. ele.click()
  40. table_list = tab.eles('xpath://*[@id="app"]/div[2]/div/div[2]/div[3]/div/div[3]/table/tbody/tr')
  41. # for tr in table_list:
  42. # # td = tab.eles('@tag:td')
  43. # print(tr.texts()) # 获取所有的文本
  44. # # //*[@id="app"]/div[2]/div/div[2]/div[3]/div/div[3]/table/tbody/tr[2]/td[6]/div/a[1]
  45. # href = tr.ele('@tag()=a') # 跳转链接
  46. # href.click()
  47. # inner_page(tab)
  48. # break
  49. except Exception as e:
  50. print(f"e is => {e}")
  51. browser.quit() # 关闭浏览器
  52. browser.quit() # 关闭浏览器