[英]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.