我想抓这个网站:https://www.projets-environnement.gouv.fr/pages/home/
更准确地说,我想用div
收集id = table-wrapper
中的表。
我的麻烦是我无法用BeautifulSoup
抓住它。
这是我的代码:
url = 'https://www.projets-environnement.gouv.fr/pages/home/'
html = requests.get(url).text
soup = BeautifulSoup(html, "html5lib")
div_table = soup.findAll('div', id_='table-wrapper')
但是div_table
是None
对象。
硒可以解决吗?
答案 0 :(得分:1)
我认为您应该使用selenium
:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
url = 'https://www.projets-environnement.gouv.fr/pages/home/'
options = Options()
options.headless = True
driver = webdriver.Firefox(firefox_options=options)
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html, "html.parser")
mytable = soup.find('div', id='table-wrapper')
然后您得到那个桌子。
答案 1 :(得分:0)
正确的呼叫方式是:
soup.find("div", {"id": "table-wrapper"})