我已经try 了许多不同的方法,我发现在网上如何找到这个按钮,但每次try 后,功能给我一个空的list
.
我需要找到按钮,并点击它,以刮不同的页面.整个页面是动态加载的,第二个页面的内容直到您打开它才会加载,这意味着它们不在DOM中,直到您移动到第二个页面.这些页面也是动态的,这意味着如果你点击不同的页面,URL不会改变.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from bs4 import BeautifulSoup
import time
from selenium.webdriver.common.by import By
# Create a new instance of the Chrome driver
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
# Go to the webpage
driver.get('https://is.muni.cz/predmet/?volby=obory:4382@fakulta:1433@obdobi:podzim%202023,jaro%202024@jazyky:eng')
links = []
driver.implicitly_wait(15)
for i in range(1):
website = driver.page_source
soup = BeautifulSoup(website, 'html.parser')
links += ['https://is.muni.cz' + link['href'] for link in soup.find_all('a', class_='course_link')]
button = driver.find_elements(By.XPATH, '//a[@class="isi-zobacek-vpravo isi-inline"]')
button.click()
time.sleep(5)
i += 1
print(links)
driver.quit()
这段代码只返回一个错误,因为单击函数不起作用,因为按钮没有内容.这是一个空的list
.