第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Python激活同名窗口

Python激活同名窗口

慕桂英546537 2023-07-27 15:56:09
選擇器.org fn是錯(cuò)誤的,應(yīng)該.org.fn選擇所有具有 classorg和 的元素fn。但是,有些項(xiàng)目沒有.address這樣,您的代碼會(huì)產(chǎn)生傾斜的結(jié)果。您可以使用此示例來獲取標(biāo)題和地址(如果缺少地址,-則使用 ):import pprintimport requestsfrom itertools import chainfrom bs4 import BeautifulSoupres = requests.get('https://www.paginebianche.it/toscana/li/gommisti.html')res2 = requests.get('https://www.paginebianche.it/ricerca?qs=gommisti&dv=li&p=2')soup = BeautifulSoup(res.text, 'html.parser')soup2 = BeautifulSoup(res2.text, 'html.parser')hn = []for i in chain.from_iterable([soup.select('.item'), soup2.select('.item')]):    title = i.h2.getText(strip=True)    addr = i.select_one('[itemprop="address"]')    addr = addr.getText(strip=True, separator='\n') if addr else '-'    hn.append({'title': title, 'address': addr})    pprint.pprint(hn)印刷:[{'address': 'Via Don Giovanni Minzoni 44\n-\n57025\nPiombino (LI)',  'title': 'CENTROGOMMA'}, {'address': 'Via Quaglierini 14\n-\n57123\nLivorno (LI)',  'title': 'F.LLI CAPALDI'}, {'address': 'Via Ugione 9\n-\n57121\nLivorno (LI)',  'title': 'PNEUMATICI INTERGOMMA GOMMISTA'}, {'address': "Viale Carducci Giosue' 88/90\n-\n57124\nLivorno (LI)",  'title': 'ITALMOTORS'}, {'address': 'Piazza Chiesa 53\n-\n57124\nLivorno (LI)',  'title': 'Lo Coco Pneumatici'}, {'address': '-', 'title': 'PIERO GOMME'}, {'address': 'Via Pisana Livornese Nord 95\n-\n57014\nVicarello (LI)',  'title': 'GOMMISTA TRAVAGLINI PNEUMATICI'}, {'address': 'Via Cimarosa 165\n-\n57124\nLivorno (LI)',  'title': 'GOMMISTI CIONI AUTORICAMBI & SERVIZI'}, {'address': 'Loc. La Cerretella, 219\n-\n57022\nCastagneto Carducci (LI)',  'title': 'AURELIA GOMME'}, {'address': 'Strada Provinciale Vecchia Aurelia 243\n'             '-\n'             '57022\n'             'Castagneto Carducci (LI)',  'title': 'AURELIA GOMME DI GIANNELLI SIMONE'},...and so on.
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

要循環(huán)選擇窗口,需要執(zhí)行以下幾個(gè)步驟:

  • 使用win32gui.EnumWindows遍歷所有打開的窗口

  • 使用win32gui.GetWindowText從窗口獲取標(biāo)題欄文本

  • 使用win32com.client.DispatchSendKeys激活切換過程

  • 使用win32gui.SetForegroundWindow選擇要激活的窗口

這是代碼:

import win32com.client as win32

import win32gui

import time


title = "Untitled - Notepad2"  # cycle all windows with this title


def windowEnumerationHandler(hwnd, top_windows):

    top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))

    

top_windows = []  # all open windows

win32gui.EnumWindows(windowEnumerationHandler, top_windows)


winlst = []  # windows to cycle through

for i in top_windows:  # all open windows

   if i[1] == title:

      winlst.append(i)

      

for x in range(5):  # cycle 5 times

   for w in winlst:  # each window with selected title

       shell = win32.Dispatch("WScript.Shell")  # set focus on desktop

       shell.SendKeys('%')  # Alt key

       win32gui.SetForegroundWindow(w[0]) # bring to front, activate

       time.sleep(2)  # 2 seconds


查看完整回答
反對(duì) 回復(fù) 2023-07-27
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)