【问题标题】:Python beautifulsoup how to get the line after 'href'Python beautifulsoup 如何获取'href'之后的行
【发布时间】:2014-05-14 21:32:38
【问题描述】:

我有这段html:

<a href="http://francetv.fr/videos/alcaline_l_instant_,12163184.html"  class="ss-titre">
                                "Paris Combo"                   </a>    
<a href="http://francetv.fr/videos/jt20h_,12185324.html" class="ss-titre"> 
                            Journal         </a>

我可以得到http://francetv.fr/videos/jt20h_,12185324.html(例如,不是真实地址)但是现在, 我想使用 beautifulsoup 来获得“Paris Combo”和“Journal”。 我试过这个:

for line in soup.findAll('/a'):
              title = line.get('</a>')

我该怎么办? 谢谢

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 我已经编辑了我的问题

标签: python beautifulsoup


【解决方案1】:

您需要改为致电find_all("a")

>>> for line in soup.find_all("a"):
...     print(line.text.strip())
"Paris Combo"
Journal

【讨论】:

  • 是的,这意味着您使用的是以前版本的 BeautifulSoup。如果可以的话,您应该考虑升级到版本 4
  • 好的,因为我正在使用 Python 2.7 和 Gtk2 ...也许我会很快学习 python3...!
  • BeautifulSoup 4 也适用于 Python 2.7。它速度更快,内存占用量更大。
  • 啊,好吧!在 Ubuntu 中,包是“python-bs4”而不是“python-beautifulsoup”(v3)。感谢您的精确度
猜你喜欢
  • 1970-01-01
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 2020-03-11
  • 1970-01-01
  • 2020-03-17
  • 2019-12-23
相关资源
最近更新 更多