我正在使用硒来获取html页面元素:
这是代码:
#First we start by adding the incognito argument to our webdriver.
option = webdriver.ChromeOptions()
browser = webdriver.Chrome(executable_path="C:/Users/driver/chromedriver.exe", chrome_options=option)
browser.get("http://extracts.blalal.com/blla?blalan=vb%20d")
browser.page_source
我所拥有的是:
'<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{"Extracts":[],"NextPageUrl":"","PageCount":0}</pre></body></html>'
我想要的是:
{"Extracts":[],"NextPageUrl":"","PageCount":0}
抱歉,我已经尝试过
答案 0 :(得分:1)
尝试获取必需的内容
driver.find_element_by_tag_name('pre').text
如果要将其用作Python字典,则可能需要
import json
json.loads(driver.find_element_by_tag_name('pre').text)