【发布时间】:2018-09-13 11:11:23
【问题描述】:
我正在尝试在 BeautifulSoup 对象中提取元素。
通过指定 div 类,我得到了以下容器,我正在检查其中一个 - first_water。
water_containers = soup.find_all('div', class_ = 'display-inline-block pull-left prod-ProductCard--Image')
first_water = water_containers[0]
为了得到一个类,它给出了以下内容:
test = first_water.a
a class="" href="/ip/Nestle-Pure-Life-Purified-Water-8-Fl-Oz-24-Count/47757005" itemprop="url"> img alt="Nestle Pure Life Purified水, 8 Fl Oz, 24 Count" class="Tile-img" height="180" src="//i5.walmartimages.com/asr/d8c48736-7833-48bb-83a5-577bfc56a8b5_1.f60d9d33c9a8030ace5fd7e653190c98.jpe 180&odnHeight=180&odnBg=ffffff" width="180"/>/a
我想提取 href="..." 中的信息 /ip/Nestle-Pure-Life-Purified-Water....
我试过分区:
test.partition('href=')
test.split('href=', 1)
但它给出了错误,说“NoneType”对象不可调用。
我认为应该有更简单的方法来提取 href 中的对象。但我不太确定该怎么做。一个标签是我能得到的最低级别。
感谢您的帮助!!!
【问题讨论】:
-
请发布您到目前为止尝试过的代码和完整的错误回溯。您的问题目前非常模糊..
-
请发布您的努力和网址
-
谢谢,我尝试添加详细信息。你能看看吗? (:
标签: python html python-3.x beautifulsoup