[英]opening google searches with python
我想让我的程序打开对Google的前5个搜索。 目前,我只有打开搜索的简单Google搜索生成器。 有没有一种方法可以打开5个搜索进入新标签页然后关闭它们?
dict = readdict()
lenght = len(dict)
search_term=""
for _ in range(self.variable2.get()):
skc=randint(0,lenght)
word = dict[skc].split(',')
search_term+=word[0]+" "
url = "https://www.google.com.tr/search?q={}".format(search_term)
webbrowser.open(url)
编辑:
url = "https://www.google.com.tr/search?q={}".format(term)
webbrowser.open_new_tab(url)
打开新标签页,但是现在谁能告诉我如何单击通过打开一些google搜索EDIT得到的前5个结果,所以我想出了一个名为google的lib的出路
for url in search('"search_term', stop=5):
我也决定只用任务杀死来关闭它们,因为webbroser lib没有关闭窗口命令
使用open_new_tab
函数:
import webbrowser
search_terms = []
# ... construct your list of search terms ...
for term in search_terms:
url = "https://www.google.com.tr/search?q={}".format(term)
webbrowser.open_new_tab(url)
如果浏览器支持,这应该在新选项卡中打开每个URL。 如果没有,它将退回到为每个选项卡打开一个新窗口。
如果您在将其专门在Chrome中打开(即使是默认浏览器)时遇到问题, 请尝试将最后一行替换为:
chrome_browser = webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s")
chrome_browser.open_new_tab(url)
使用您的Chrome安装的等效位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.