pychrome讀取頁面的原始碼
作者: fase 日期: 2023-09-09 17:50
之前一篇讀取的是元素,這篇讀的原始碼
import pychrome
browser = pychrome.Browser(url = "http://127.0.0.1:9222")
tabs = browser.list_tab()
if not tabs:
tab = browser.new_tab()
else:
tab = tabs[0]
tab.start()
tab.Page.enable()
tab.Page.navigate(url=f"https://example.com")
tab.wait(5)
#讀取頁面原始檔
resource_tree = tab.Page.getResourceTree()
main_frame = resource_tree['frameTree']['frame']
main_frame_id = main_frame['id']
page_source = tab.Page.getResourceContent(frameId = main_frame_id, url = "https://example.com")
print(page_source['content'])
評論: 0 |
引用: 0 |
閱讀: 250 |
回到頁首