国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術(shù)及教程分享平臺!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python通過tkinter實現(xiàn)百度搜索的示例代碼

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

2021-10-07 10:43wx_zhu6201976 Python

這篇文章主要介紹了Python通過tkinter實現(xiàn)百度搜索的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
百度搜索可視化
"""
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()

補充:python模擬百度搜索點擊鏈接

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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實現(xiàn)百度搜索的示例代碼的文章就介紹到這了,更多相關(guān)Python tkinter百度搜索內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://blog.csdn.net/zhu6201976/article/details/103941292

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产原创精品视频 | 午夜草民福利电影 | 国产精品亚洲综合 | 在线观看日韩精品 | 蜜桃香蕉视频 | 欧美国产日韩一区 | 国产精品久久久久久久久久久久久久 | 99精品久久| 日本一区二区三区免费观看 | 国产精品视频久久久 | 久久不卡| 综合久 | 亚洲一区二区三区免费观看 | 国产精品69毛片高清亚洲 | 国产一区二| 国产精品免费在线 | 亚洲精品一区在线观看 | 最新国产视频 | 中国大陆一级毛片 | 一区二区三区在线不卡 | 国产精品成人一区二区三区 | 俺去俺来也在线www色官网 | 亚洲精品久久久久久一区二区 | 亚洲精品一区二区三区蜜桃久 | 国产成人一区二区三区在线观看 | 91视频在线| 午夜爽爽爽 | 精品久久一区二区 | 在线观看一区二区三区四区 | 一级特黄录像免费播放全99 | av免费在线观看网站 | 成人网在线观看 | 秋霞午夜 | 国产一级一级毛片女人精品 | bxbx成人精品一区二区三区 | 涩涩视频在线看 | 欧美精品亚洲 | 天天操天天干天天 | 91亚洲精品乱码久久久久久蜜桃 | 成年人免费观看在线视频 | 欧美日韩综合在线 |