[Crawler Tips] Solve the problem of unable to locate the iframe data frame in the page

Problem scenario

Similar business online query page when using selenium for data capture, data will be captured in the frame data box, located directly inside the xpath element is not the result of acquisition, so the data frame to be positioned inside the box.
Insert picture description here

Processing method

import warnings
warnings.filterwarnings("ignore")
from selenium import webdriver#加载驱动
from selenium.webdriver.common.keys import Keys#控制按键

phjs=R"你模拟器的路径"
driver = webdriver.PhantomJS(phjs)#运行浏览器驱动打开浏览器
driver.get("http://www.gjsy.gov.cn/cxzl/")
driver.switch_to_default_content()

# 重点在这里
frame = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_frame(frame)
driver.page_source

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_20288327/article/details/113772218