简体   繁体   中英

What is the Selenium equivalent of using Google Chrome Developer Tools and clicking "Copy OuterHTML" on the outermost HTML element?

Previously, I was just using Google Chrome and its Developer Tools to Copy/Paste the HTML Code of a certain website.

I was just manually using Google Chrome Developer Tools and right-clicking on the outermost HTML class and pressing "Copy OuterHTML" and then I would paste that into a notepad text file and get to work on it.

But now, I want to automate this process. I want to use Selenium to grab the HTML.

I have used the following, but they do not get me the same exact result (they are missing some internal html elements and stuff) as Copying the HTML Code Manually using Google Chrome:

driver.page_source driver.execute_script("return document.documentElement.outerHTML")

Any other ideas?

Did you tried to use Beautiful Soup ? It's a scrapper that grab all the HTML from a page, and then you can select elements like with Selenium. But you can't navigate the page to trigger JS or click on buttons.

You can also try

driver.find_element_by_tag_name('html').get_attribute('outerHTML')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM