Skip to content

about

官档:

https://www.drissionpage.cn/get_start/installation

https://gitee.com/zhaoya-gitee/DrissionPage

元素操作

python
# 获取textarea和input框的值
page.ele('tag:textarea').value

打开指定浏览器

python
from DrissionPage import WebPage, ChromiumOptions
from DrissionPage.common import By
from lxml import etree
 
cp = ChromiumOptions().set_paths(browser_path=r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")
page = WebPage("d", chromium_options=cp)
print("当前页面对象模式11", page.mode)
page.listen.start("office/jsp/zdsswfaj/wwquery")
page.get("http://beijing.chinatax.gov.cn/bjsat/office/jsp/zdsswfaj/wwquery.jsp", retry=3, interval=2, timeout=15)
page.ele("text=东城").click()
print(page.ele("text:项查询结果").text.strip().rstrip("页").strip())
for packet in page.listen.steps():
    res_text = packet.response.body
    if packet.method == "POST":
        al_res = etree.HTML(res_text)
        print(packet.method, packet.request.postData, packet.url)
        for tr in al_res.xpath("//tr"):
            tds = [td.strip() for td in tr.xpath(".//td/text()")]
            print(tds)
        cur_page = page.ele("text:项查询结果").text.strip().split("/")[0][-1]
        print(f"当前是弟{page.ele('text:项查询结果').text.strip().rstrip('页').strip()}")
        page("text=下一页").click()
        # loc2 = (By.XPATH, xpath)
        # ele = page.ele(loc2)
        # ele.click()
        if cur_page == "3":
            break