问题描述
导入操作系统
os.system('chrome sololearn')
#Chrome搜索sololearn / #我希望Chrome搜索sololearn
解决方法
您可以使用Selenium做到这一点并自动执行Google搜索 首先在您的闲置或pycharm中安装硒 硒
pip install selenium
安装
Chromedriver
从here下载chrome浏览器(选择系统的版本) 下载后,将其解压缩,然后将文件复制到脚本的文件夹中。
from selenium import webdriver
# Taking input from user
search_string = input("Input the URL or string you want to search for:")
# This is done to structure the string
search_string = search_string.replace(' ','+')
# Assigning the browser variable with chromedriver of Chrome.
browser = webdriver.Chrome('chromedriver')
for i in range(1):
matched_elements = browser.get("https://www.google.com/search?q=" +
search_string + "&start=" + str(i))