我想从网站获取数据并使用selenium存储html代码。我写了以下代码:
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get(r'http://www.example.com')
driver.page_source #get the html code
我该怎么办?
谢谢。
答案 0 :(得分:0)
试试这个:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(r'http://www.example.com')
driver.page_source #get the html code
elem = driver.find_element_by_xpath("//*")
source = elem.get_attribute("outerHTML")
driver.quit()