【问题标题】:Beautiful Soup_ extraction within class美丽的汤_课堂内提取
【发布时间】: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


【解决方案1】:

试试这个:

link = first_water.a['href']

【讨论】:

  • 哇。有用!非常感谢你~~~非常感谢你的帮助,drec4s(:祝你有美好的一天。
猜你喜欢
  • 1970-01-01
  • 2020-01-19
  • 2021-04-03
  • 2016-09-11
  • 2015-05-08
  • 2021-05-24
  • 2015-10-21
  • 1970-01-01
  • 2018-07-31
相关资源
最近更新 更多