Selenium with Python, how do I get page output after running a script?

I'm not sure how to find this information, I have found several tutorials so far about using Python with selenium, but none of them affect this. I can run some basic test scripts using python, automate selenium, but it just shows the browser window for a few seconds and then closes it. I need to get the browser output to a string / variable (ideally), or at least save it to a file so that python can do other things on (parse it, etc.). I would appreciate it if someone could point me to resources on how to do this. Thanks

+3
source share
3 answers

There is a method in Java Selenium.getHtmlSource(), most likely it is also available in Python. It returns the source of the current page as a string, so you can do whatever you want with it.

+2
source

using Selenium Webdriver and Python, you simply access the property .page_sourceto get the source of the current page.

for example using a driver Firefox():

from selenium import webdriver


driver = webdriver.Firefox()
driver.get('http://www.example.com/')

print(driver.page_source)

driver.quit()
+3
source

, , , .

firefox.

1) firefox ( , , firefox), , Google, ,

2) firefox: https://addons.mozilla.org/en-US/firefox/addon/2704/ ( ), , .

3), then just start the selenium server to use the profile you created (below is an example for Linux)

cd /root/Downloads/selenium-remote-control-1.0.3/selenium-server-1.0.3 
java -jar selenium-server.jar -firefoxProfileTemplate /path_to_your_firefox_profile/

Here it is, now it will save all pages for a given domain name whenever selenium visits them, selenium really creates a bunch of garbage pages, so you can simply delete them with a simple parsing of regular expressions and it is up to you, from there how to manage saved pages

+2
source

Source: https://habr.com/ru/post/1761629/