濮阳杆衣贸易有限公司

主頁 > 知識庫 > Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼

Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼

熱門標(biāo)簽:淮安呼叫中心外呼系統(tǒng)如何 看懂地圖標(biāo)注方法 廣東旅游地圖標(biāo)注 打印谷歌地圖標(biāo)注 電話外呼系統(tǒng)招商代理 佛山通用400電話申請 京華圖書館地圖標(biāo)注 蘇州人工外呼系統(tǒng)軟件 電話機(jī)器人貸款詐騙

本文主要介紹了Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼,分享給大家,具體如下:

"""
百度搜索可視化
"""
import tkinter
 
import win32api
from selenium.webdriver import Chrome
 
entry = None
 
 
def callback():
    global entry
    keywords = entry.get()
    if not keywords:
        win32api.MessageBox(0, '請輸入搜索關(guān)鍵字', '提示', 0)
        return
    chrome = Chrome()
    chrome.get('https://www.baidu.com/')
    chrome.find_element_by_id('kw').send_keys(keywords)
    chrome.find_element_by_id('su').click()
 
    # bilibili關(guān)鍵字搜索
    # chrome.get('https://www.bilibili.com/')
    # chrome.find_element_by_xpath('//form[@id="nav_searchform"]/input').send_keys(keywords)
    # chrome.find_element_by_xpath('//div[@class="nav-search-btn"]/button').click()
 
 
def main():
    global entry
    tk = tkinter.Tk()
    # tk.resizable(width=False,height=False)  # 固定窗體大小?無效
    tk.title('百度搜索')
 
    # 1.設(shè)置窗體居中
    # screenwidth = tk.winfo_screenwidth()  # 獲取屏幕寬度
    # screenheight = tk.winfo_screenheight()  # 獲取屏幕高度
    # # 計算窗體大小,位置參數(shù),width,height:窗體寬高
    # width = 100
    # height = 50
    # size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    # tk.geometry(size)  # 設(shè)置窗體位置為屏幕居中
 
    # 2.設(shè)置窗體右下角,無效
    # screenwidth = tk.winfo_screenwidth()  # 獲取屏幕寬度
    # screenheight = tk.winfo_screenheight()  # 獲取屏幕高度
    # print(screenwidth,screenheight)
    # # 計算窗體大小,位置參數(shù),width,height:窗體寬高
    # width = 100
    # height = 50
    # size = '%dx%d+%d+%d' % (width, height, (screenwidth - width), (screenheight - height))
    # tk.geometry(size)  # 設(shè)置窗體位置為屏幕右下角
 
    # 獲取窗體x,y
    # tk.update()
    # print(tk.winfo_x())
    # print(tk.winfo_y())
 
    tk.geometry('+0+0')  # 固定屏幕左上角
    # tk.geometry('+1440+770')
 
    entry = tkinter.Entry(tk)
    entry.pack()
 
    button = tkinter.Button(tk, text='百度一下', command=callback)
    button.pack()
 
    tk.mainloop()
 
 
if __name__ == '__main__':
    main()

補(bǔ)充:python模擬百度搜索點(diǎn)擊鏈接

# coding: utf-8
import os
import time
import requests
import urllib.parse
from bs4 import BeautifulSoup
from urllib.parse import urlparse
from fake_useragent import UserAgent
from multiprocessing.pool import ThreadPool
LOCATIONS = {}
GLOBAL_THREAD = 500
GLOBAL_TIMEOUT = 50
def get_links(keyword, generator, pages):
links = []
for page in range(int(pages.split("-")[0]), int(pages.split("-")[1]) + 1):
for genera in range(int(generator.split("-")[0]), int(generator.split("-")[1]) + 1):
links.append(
"http://www.baidu.com.cn/s?wd=" + urllib.parse.quote(keyword + str(genera)) + "pn=" + str(page * 10))
return links
def get_page(url):
headers = {"user-agent": UserAgent().chrome}
req = requests.get(url, headers=headers)
req.encoding = "utf-8"
soup = BeautifulSoup(req.text, "lxml")
for link in soup.select("div.result > h3.t > a"):
req = requests.get(link.get("href"), headers=headers, allow_redirects=False)
if "=" in req.headers["location"]:
root = urlparse(req.headers["location"]).netloc
LOCATIONS[root] = req.headers["location"]
def baidu_search():
try:
os.system("cls")
print("-" * 56 + "\n")
print("| BaiduSearch Engine By 美圖博客[https://www.meitubk.com/] |\n")
print("-" * 56 + "\n")
keyword = input("Keyword: ")
generator = input("Generator(1-10): ")
pages = input("Pages(0-10): ")
start = time.time()
pool = ThreadPool(processes=GLOBAL_THREAD)
pool.map(get_page, get_links(keyword, generator, pages))
pool.close()
pool.join()
end = time.time()
path = r"D:\Desktop\result.txt"
save_result(path)
print("\nSava in %s" % path)
print("Result count: %d" % len(LOCATIONS.values()))
print("Running time: %ds" % (end - start))
except:
print("\nInput Error!")
exit(0)
def save_result(path):
with open(path, "w") as file:
for url in list(LOCATIONS.values()):
file.write(url + "\n")
baidu_search()

到此這篇關(guān)于Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼的文章就介紹到這了,更多相關(guān)Python tkinter百度搜索內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python tkinter模塊彈出窗口及傳值回到主窗口操作詳解
  • Python升級提示Tkinter模塊找不到的解決方法
  • python的tkinter布局之簡單的聊天窗口實(shí)現(xiàn)方法
  • Python Tkinter基礎(chǔ)控件用法
  • python TKinter獲取文本框內(nèi)容的方法
  • python3.5 tkinter實(shí)現(xiàn)頁面跳轉(zhuǎn)
  • 對python Tkinter Text的用法詳解
  • 對Python 窗體(tkinter)樹狀數(shù)據(jù)(Treeview)詳解
  • Python tkinter label 更新方法
  • python3.6 +tkinter GUI編程 實(shí)現(xiàn)界面化的文本處理工具(推薦)
  • Python中使用Tkinter模塊創(chuàng)建GUI程序?qū)嵗?/li>
  • 使用Python中的tkinter模塊作圖的方法

標(biāo)簽:畢節(jié) 中山 駐馬店 江蘇 湖州 股票 呼和浩特 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼》,本文關(guān)鍵詞  Python,通過,tkinter,實(shí)現(xiàn),百度,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    双峰县| 达州市| 萨嘎县| 永宁县| 平原县| 长岛县| 临城县| 新竹县| 广河县| 印江| 理塘县| 翼城县| 丰原市| 罗江县| 恩平市| 芒康县| 大足县| 宕昌县| 杂多县| 堆龙德庆县| 班玛县| 济南市| 柯坪县| 弋阳县| 富阳市| 平谷区| 博白县| 赫章县| 金平| 左云县| 盐山县| 临沂市| 德格县| 隆安县| 武强县| 湘乡市| 射阳县| 扶风县| 布尔津县| 芷江| 阿克苏市|