开发者社区 > 云原生 > 容器服务 > 正文

无法从网页中删除容器

我正在尝试从电子商务网页上练习网络报废。我已经确定了容器的类名(包含每个产品的单元格)'c3e8SH'。然后,我使用以下代码来废弃该网页中的所有容器。之后,我用来len(containers)检查网页中的容器数量。

然而,它返回0.

import bs4
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

my_url = 'https://www.lazada.sg/catalog/?spm=a2o42.home.search.1.488d46b5mJGzEu&q=switch%20games&_keyori=ss&from=search_history&sugg=switch%20games_0_1'

# opening up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()

#html parsing
page_soup = soup(page_html, 'html.parser')

#grabs each product
containers = page_soup.find_all('div', class_='c3e8SH')
len(containers)

展开
收起
一码平川MACHEL 2019-01-23 13:38:43 1881 0
1 条回答
写回答
取消 提交回答
  • 没有确定div。

    'c3e8SH'

    你能再次查看网站吗?


    尝试使用其他解析器。我推荐lxml。所以你创建的page_soup行将是: page_soup = soup(page_html, 'lxml')

    2019-07-17 23:26:35
    赞同 展开评论 打赏
问答分类:
问答标签:

国内唯一 Forrester 公共云容器平台领导者象限。

相关电子书

更多
阿里云文件存储 NAS 在容器场景的最佳实践 立即下载
何种数据存储才能助力容器计算 立即下载
《容器网络文件系统CNFS》 立即下载