From 279c7b0a512a71a7075e64aff2eb33d814559854 Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Fri, 29 Nov 2024 20:49:50 +0530 Subject: [PATCH] Added a Wikipedia search script --- .../Day-48/interaction.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Visual Studio Code Projects/Day-48/interaction.py diff --git a/Visual Studio Code Projects/Day-48/interaction.py b/Visual Studio Code Projects/Day-48/interaction.py new file mode 100644 index 0000000..202355c --- /dev/null +++ b/Visual Studio Code Projects/Day-48/interaction.py @@ -0,0 +1,23 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +chrome_options = webdriver.ChromeOptions() +chrome_options.add_experimental_option("detach", True) + +driver = webdriver.Chrome(options=chrome_options) + +driver.get("https://en.wikipedia.org/wiki/Main_Page") + +# wikipedia_article_count = driver.find_element(By.XPATH, value='//*[@id="articlecount"]/a[1]') +# it is possible to use the method given above but the method given below should also get the job done. +wikipedia_article_count = driver.find_element(By.CSS_SELECTOR, value="#articlecount a") + +# print(wikipedia_article_count.text) + +all_portals = driver.find_element(By.LINK_TEXT, value="Content portals") + +search = driver.find_element(By.NAME, value="search") +search.send_keys("your-search-here", Keys.ENTER) + +# driver.quit() \ No newline at end of file