【发布时间】:2020-04-06 11:06:01
【问题描述】:
好吧,正如标题所示,我正在尝试从网站上抓取一些数据(example) 使用 Selenium,但是我无法从 Pro Results 表中获取隐藏在每一行中的数据,该表显示当您单击“显示详细信息”按钮 (+) 时。
这是我的代码:
from bs4 import BeautifulSoup
from selenium import webdriver
# Set some Selenium Options
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# Webdriver
wd = webdriver.Chrome('chromedriver',options=options)
# URL
url = 'https://www.tapology.com/fightcenter/fighters/30449-sultan-aliev'
# Load URL
wd.get(url)
# Get HTML
soup = BeautifulSoup(wd.page_source, 'html.parser')
# All rows of the Pro Record table
rows = soup.findAll('div', {'class': 'result'})
print(len(rows))
# [Out] 18
# Try to find all hidden data
hidden = soup.findAll('div', {'class': 'detail tall'})
print(hidden)
# [Out] []
如您所见,我可以轻松获取表格的行,但是当我尝试获取隐藏数据时,我找不到获取它的方法。
我对 Selenium 也不是很熟悉,因此欢迎任何指导。
【问题讨论】:
标签: python selenium web-scraping