【问题标题】:BeautifulSoup 4 doesn't grab any element from the websiteBeautifulSoup 4 没有从网站上抓取任何元素
【发布时间】:2018-12-23 22:17:21
【问题描述】:

我使用以下代码从网站获取数据。它不会从网站上抓取任何元素。

import bs4
from urllib.request import urlopen as ureq
from bs4 import BeautifulSoup as soup
my_url='website name'
uclient=ureq(my_url)
page_html=uclient.read()
uclient.close()
page_soup=soup(page_html,"html.parser")
containers=page_soup.find_all("divs",{"class":"item-container"})
len(containers)

容器的长度显示为0。请帮忙。

【问题讨论】:

标签: python web web-scraping beautifulsoup


【解决方案1】:

标签名称应该是div 而不是divs

>>> len(page_soup.find_all('div',{'class':'item-container'}))
12

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    相关资源
    最近更新 更多