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.
|
|
from DrissionPage import Chromium, ChromiumOptions
class DPModel(): def __init__(self, link): self.login_qr = "" self.login_link = link self.browser = self.init_browser() self.tab = None
def init_browser(self): co = ChromiumOptions() co.set_argument("--remote-debugging-port", "9222") browser = Chromium(co) # 创建浏览器对象 browser.set.retry_times(10) # 设置整体运行参数 return browser
def get_login_qr(self): try: self.tab = self.browser.latest_tab # 获取Tab对象 self.tab.get("https://etax.chinatax.gov.cn/webstatic/login") qr_code = self.tab.ele('xpath://*[@id="app"]/div[2]/div/div/div[2]/div[3]/div[1]/img').attr("src") self.login_qr = qr_code except Exception as e: print(f"e is => {e}") self.browser.quit() # 关闭浏览器
return self.login_qr
def get_content(self): try: self.tab.wait.eles_loaded('xpath://*[@id="app"]/div[1]/div/div[2]/ul/li[3]/a', timeout=30) ele = self.tab.ele('xpath://*[@id="app"]/div[1]/div/div[2]/ul/li[3]/a') # 我要查询 ele.click() self.tab.ele('xpath://*[@id="app"]/div[2]/div/div/div[1]/div[2]/a[1]').click() # 申报查询
text = self.tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[2]/div[1]/div[1]').text # 待缴税款 print(text) text1 = self.tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[2]/div[1]/div[2]').text # 可申请退税金额 print(text1) ele = self.tab.ele('xpath://*[@id="app"]/div[2]/div/div[2]/div[1]/label[2]/span') # 已完成标签 ele.click()
table_list = self.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() self.tab.wait.load_start() # 等待 self.inner_page(self.tab) break
except Exception as e: print(f"e is => {e}") self.browser.quit() # 关闭浏览器
def inner_page(self, 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() # 跳转下载 a_tab.wait.doc_loaded() # 等待文档加载完毕 page.get_screenshot(path='tmp', name='pic.jpg', full_page=False) # 下载发票 break
def __del__(self): print("?????") # self.browser.quit() # 关闭浏览器
if __name__ == '__main__': url = "https://etax.chinatax.gov.cn/webstatic/login" d = DPModel(url) qr_code = d.get_login_qr() # 获取验证码 print(qr_code) pass
|