繁体   English   中英

web 使用 selenium 和 beautifulsoup 进行抓取

[英]web scraping using selenium and beautifulsoup

我正在尝试网络抓取 grofer 和 bigbasket 信息,但我在使用 findAll() function 时遇到了问题。当我使用 len(imgList) 时,长度总是返回 0。它总是显示空列表如何解决?可以有人帮我吗? 我在 grofer 中得到状态代码 403

from bs4 import BeautifulSoup
url = 'https://grofers.com/cn/grocery-staples/cid/16'
driver = webdriver.Chrome(r'C:\Users\HP\data\chromedriver.exe')
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html,'html.parser')
data = soup.findAll('plp-product__name')
print(data)
from bs4 import BeautifulSoup
response = requests.get('https://grofers.com/cn/grocery-staples/cid/16')
response
content = response.content
data = BeautifulSoup(content,'html5lib')
read = data.findAll('plp-product__name ')
read```

在输出中我得到: []

你没有包括

from selenium import webdriver 
driver = webdriver.Chrome(executable_path=r'C:\Users\HP\data\chromedriver.exe')

尝试

data = soup.select('div.plp-product__name ')

或者替代地

data = soup.find_all("div",class_="plp-product__name")

请注意,正确的方法是find_all而不是findAll ,因为它在 bs4 库中已被弃用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM