【问题标题】:web scraping using selenium and beautifulsoup使用 selenium 和 beautifulsoup 进行网页抓取
【发布时间】:2020-07-17 09:51:21
【问题描述】:

我正在尝试从网络上抓取 grofer 和 bigbasket 信息,但我在 findAll() 函数中遇到了问题。当我使用 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```

在输出中我得到: []

【问题讨论】:

    标签: python selenium web-scraping


    【解决方案1】:

    你没有加入

    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 库中已被弃用。

    【讨论】:

      猜你喜欢
      • 2020-09-13
      • 1970-01-01
      • 2022-11-07
      • 2021-09-10
      • 2020-08-09
      • 2017-06-11
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多