美好的一天!我正在尝试从此网站https://www.flashscore.com/player/nadal-rafael/xUwlUnRK/results/抓取有关比赛的信息 使用代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
options = Options()
options.add_argument("--headless")
profile = webdriver.FirefoxProfile()
profile.set_preference('permissions.default.image', 2)
driver = webdriver.Firefox(firefox_options = options, firefox_profile=profile)
driver.implicitly_wait(40)
driver.get('https://www.flashscore.com/player/nadal-rafael/xUwlUnRK/results/')
src = driver.page_source
soup = BeautifulSoup(src, "html.parser")
table = soup.prettify()
f = open('text.txt', 'w', encoding='utf-8')
f.write(table)
f.close()
driver.close()
但最终所有文本都包含标记中的匹配项,并且ID =“ fs-results_s”消失
<div class="fs-passive fs-table tournament-page" id="fs-results_s">
</div>
。我尝试使用Chrome,但这无济于事。 可能是什么错误?