简体   繁体   中英

How to search on Google with Selenium in Python?

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

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

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

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM