2 回答
TA贡献1798条经验 获得超3个赞
试试这个:
iframe = driver.find_elements_by_tag_name('iframe')
for i in range(0, len(iframe)):
f = driver.find_elements_by_tag_name('iframe')[i]
driver.switch_to.frame(i)
# your work to extract link
text = driver.find_element_by_tag_name('body').text
print(text)
driver.switch_to_default_content()
TA贡献1784条经验 获得超2个赞
你应该用
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to.frame(iframe)
# your work to extract link
driver.switch_to_default_content()
用于多个网址
find_elements_by_tag_name将返回一个数组。所以用于循环
iframe = driver.find_elements_by_tag_name('iframe')
for i in iframe:
driver.switch_to.frame(i)
# your work to extract link
driver.switch_to_default_content()
只获取文字
用
text = driver.find_element_by_tag_name('body').text
后 driver.switch_to.frame(i)
添加回答
举报