1 回答

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個贊
我的解決方案:
#Closing popup for Portugese betting site
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
URL = "https://www.betano.pt/sport/futebol/ligas/17083r/"
# Browser options
options = Options()
options.headless = True
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
browser = webdriver.Firefox(firefox_profile=firefox_profile)
browser.get(URL)
##### Copy this part into your own code #####
try:
browser.find_element_by_xpath('//button[@class="sb-modal__close__btn uk-modal-close-default uk-icon uk-close"]').click() # Click pop-up close button
print("Pop-up closed.")
except:
print("Pop-up button not found.")
#########
關(guān)閉此彈出窗口:
請記住,這依賴于通過非常具體的類名稱來查找按鈕。您需要將最后的 try- except 調(diào)整為您自己的代碼。
添加回答
舉報(bào)