1

I'm really new to web scraping. Is there anyone that could tell me how to search on google.com with Selenium in Python?

3 Answers 3

1

In order to search something on google, try this:

from selenium import webdriver

driver = webdriver.Chrome()

driver.get('https://www.google.com/')

textbox = driver.find_element_by_xpath('//input[@name=\"q\"]')

textbox.send_keys('who invented python\n')
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, @Sushil I tried the code but this error occoured: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input"} It might be something with the fact that the Cookie Alert pops up?
1

Selenium probably isn't the best. other libraries/tools would work better. BeautifulSoup is the first one that comes to mind

1 Comment

Thank you I'll look into that
1

Don't use Selenium, there are other tools more suitable for that. Be aware that Google does not look upon favorably on scraping their search results:

Google does not take legal action against scraping, likely for self-protective reasons. However, Google is using a range of defensive methods that makes scraping their results a challenging task.

Source: https://en.wikipedia.org/wiki/Search_engine_scraping

2 Comments

What other tools would you recommend?
I never used it, but github.com/scrapy/scrapy, dzone.com/articles/getting-started-with-scrapy looks worthwile to try. But also BeautiulSoup should be OK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.