I made a simple automation selenium script which takes user input and based on that searches the web. Then it clicks on the first given link/website and copies/outputs all the text from the website into the command line. Now I want to save this text into a notepad or word. So I'm wondering if this is possible with selenium?
I tried searching for a method how to do this but I couldn't find anything so now I wonder if its possible to do that with selenium.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
subjectName = str(input("Enter the name of the subject: "))
driver = webdriver.Chrome('C:/Users/ishak/Downloads/chromedriver')
driver.get('https://www.google.com')
def subject_search(subject):
elem = driver.find_element_by_name('q')
elem.send_keys(subject)
elem.send_keys(Keys.RETURN)
subject_search(subjectName)
def given_results():
results = driver.find_elements_by_xpath(
'//div[@class="r"]/a/h3') # finds webresults
results[0].click() # clicks the first one
given_results()
myText = driver.find_element_by_xpath(
"//*[@id='mw-content-text']").text
print("Your text is: ", myText)