我想让我的程序打开谷歌的前5个搜索。目前,我只有一个简单的谷歌搜索生成器,打开搜索。有没有一种方法可以打开新标签中的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)
打开新的选项卡,但现在有人能告诉我如何点击前5个结果,这是我通过打开google搜索编辑获得的,所以我想出了一个方法,叫做google。
for url in search('"search_term', stop=5):
此外,我还决定只使用任务杀死来关闭它们,因为webbroser没有关闭窗口命令
发布于 2016-07-19 15:37:20
使用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中具体打开它,即使是默认浏览器(see here),请尝试将最后一行替换为:
chrome_browser = webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s")
chrome_browser.open_new_tab(url)
使用与Chrome安装相同的位置。
https://stackoverflow.com/questions/38459894
复制相似问题