使用Selenium在Python上进行网络抓取时找不到div类

史蒂文·坎登

我以说过类似的问题为开头,但是没有一种解决方案对我有用

所以我在我的html页面中寻找一个特定的类,但是我总是返回None值。我在这里看到过一些描述相同问题的文章,但是没有一种解决方案对我有用。这是我的尝试-我正在寻找带有其名称的播放器标签,即“ Chase Young”

from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import requests

url = "https://www.nfl.com/draft/tracker/prospects/allPositions?
college=allColleges&page=1&status=ALL&year=2020"

soup = BeautifulSoup(url.content, 'lxml')
match = soup.find('div', class_ = 'css-gu7inl')
print(match)
# Prints None

我尝试了另一种方法来找到匹配项,但仍返回None:

match = soup.find("div", {"class": "css-gu7inl"} # Print match is None

似乎html文件未包含所有网页,因此我尝试使用硒,因为我在类似的帖子中看到了推荐,但仍然没有得到任何结果:

driver = webdriver.Chrome("chromedriver")
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'lxml')
items=soup.select(".css-gu7inl")
print(items) # Empty list

我在这里做错了什么?

昆杜克

数据是由Java脚本呈现的,因此Induce WebDriverWait()并使用visibility_of_all_elements_located()等待元素可见

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup

url='https://www.nfl.com/draft/tracker/prospects/allPositions?college=allColleges&page=1&status=ALL&year=2020'
driver = webdriver.Chrome()
driver.get(url)
WebDriverWait(driver,20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,'.css-gu7inl')))
soup = BeautifulSoup(driver.page_source, 'lxml')
items=soup.select(".css-gu7inl")
Players=[item.select_one('a.css-1fwlqa').text for item in items]
print(Players) 

输出

['chase young', 'jeff okudah', 'derrick brown', 'isaiah simmons', 'joe burrow', "k'lavon chaisson", 'jedrick wills', 'tua tagovailoa', 'ceedee lamb', 'jerry jeudy', "d'andre swift", 'c.j. henderson', 'mekhi becton', 'mekhi becton', 'patrick queen', 'henry ruggs iii', 'henry ruggs iii', 'javon kinlaw', 'laviska shenault jr.', 'yetur gross-matos']

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在网络上进行抓取时找不到表格内容(隐藏表格)

找不到div类的网络抓取选择器

使用puppeteer进行网络抓取找不到CSS标签

使用python的网页抓取找不到网络链接

使用 BeautifulSoup 或 Selenium 抓取网站时找不到数据

使用Selenium和Python进行网络抓取时出现问题

如何在使用python进行网络抓取时访问类HTML中的特定对象

FeatureNotFound:找不到具有您请求的功能的树构建器–使用Pandas进行网络抓取

使用python在Android上进行网页抓取

未知错误:尝试通过Selenium使用ChromeDriver Chrome在Jenkins上进行Maven测试时找不到Chrome二进制文件

使用 Selenium 进行 Python 抓取

Selenium 找不到类来迭代和抓取文本

使用python进行网页抓取以打印类div

在MacOSX上进行静态链接时找不到符号

使用python+Selenium登录,但是找不到div

使用 Python 和 Beautiful Soup 进行抓取时 div 的问题

使用bs4进行网络抓取时如何查找特定的类?

在Python上进行网页抓取

使用python和BeautifulSoup进行网络抓取

使用登录进行简单的python网络抓取

使用python进行网络抓取中的“AttributeError”

Selenium Webdriver用python抓取动态页面找不到元素

使用 BeautifulSoup 进行网页抓取,在 html 中找不到表格

Heroku:使用Selenium时找不到chromedriver

在 Python 中使用 Selenium 进行网页抓取

使用python -selenium进行Web抓取

使用Python进行网络抓取时如何删除熊猫数据框中的字符?

使用Python进行网络抓取时显示所有搜索结果

使用python-requests进行网络抓取时如何获取丢失的HTML数据