国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

瀏覽:73日期:2022-06-22 18:31:50

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

'''百度搜索可視化'''import tkinter import win32apifrom selenium.webdriver import Chrome entry = None def callback(): global entry keywords = entry.get() if not keywords:win32api.MessageBox(0, ’請(qǐng)輸入搜索關(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) # 固定窗體大小?無(wú)效 tk.title(’百度搜索’) # 1.設(shè)置窗體居中 # screenwidth = tk.winfo_screenwidth() # 獲取屏幕寬度 # screenheight = tk.winfo_screenheight() # 獲取屏幕高度 # # 計(jì)算窗體大小,位置參數(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è)置窗體右下角,無(wú)效 # screenwidth = tk.winfo_screenwidth() # 獲取屏幕寬度 # screenheight = tk.winfo_screenheight() # 獲取屏幕高度 # print(screenwidth,screenheight) # # 計(jì)算窗體大小,位置參數(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-8import osimport timeimport requestsimport urllib.parsefrom bs4 import BeautifulSoupfrom urllib.parse import urlparsefrom fake_useragent import UserAgentfrom multiprocessing.pool import ThreadPoolLOCATIONS = {}GLOBAL_THREAD = 500GLOBAL_TIMEOUT = 50def 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 linksdef 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']).netlocLOCATIONS[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:Desktopresult.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通過(guò)tkinter實(shí)現(xiàn)百度搜索的示例代碼的文章就介紹到這了,更多相關(guān)Python tkinter百度搜索內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: 百度 Python
相關(guān)文章:
主站蜘蛛池模板: 国产精品资源手机在线播放 | 最新亚洲一区二区三区四区 | 久久成人精品视频 | 国产精选在线 | 日本在线观看免费视频网址 | 欧美区一区 | 国产99久久久久久免费看 | 男人又粗又硬桶女人免费 | 精品视频在线观看一区二区三区 | 欧美成人高清在线视频大全 | 99久久精品久久久久久婷婷 | 亚洲人成综合网站在线 | 免费一区二区三区在线视频 | 精品一区二区三区免费观看 | 久9视频这里只有精品 | 九九成人 | 久久这里有精品视频 | 亚洲欧美日韩国产综合 | 成年美女黄网站色视频大全免费 | 久热久草| 国产精品二区高清在线 | 黄色a三级免费看 | 欧美乱大交xxxxx | 久久精品国产精品亚洲人人 | 日韩欧美高清在线 | 爽死你个放荡粗暴小淫货双女视频 | 99久久国产综合精品五月天 | 91精品国产91热久久久久福利 | 成年片免费网址网站 | 国产精品黄网站免费观看 | 免费观看的毛片手机视频 | 在线高清国产 | 精品久久久久久久久久中文字幕 | 亚洲欧美第一 | 亚洲一区2区三区4区5区 | 碰超在线观看 | 一级毛片区 | 91影视永久福利免费观看 | 国产精品漂亮美女在线观看 | 国产高清一区二区三区免费视频 | 中文字幕乱码无线码在线 |