G
G
GH0st_is_HAcker2021-09-15 21:44:07
Parsing
GH0st_is_HAcker, 2021-09-15 21:44:07

Why is Selenium script fetching data from the wrong page?

Here is my code:

import time

from selenium import webdriver

from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path="H:\Pycharm projects\Web-driver\chromedriver.exe")


driver.get("https://www.youtube.com")

search_bar = driver.find_element(By.XPATH, """//input[@id = "search"]""")

search_bar.send_keys("gachi memes")

search_button = driver.find_element(By.XPATH, """//*[@id="search-icon-legacy"]""")

search_button.click()

video = driver.find_elements(By.ID, "video-title")

for i in range(len(video)):
    print(video[i].text)
    if i == 10:
        break

1) This code should go to YouTube
2) enter "gachi memes" in the search
3) press search
4) collect the names of the first ten
videos
Perhaps this is due to the fact that I did not install the driver correctly (If I have Windows 10)
Or I screwed up in the code

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question