【发布时间】:2015-12-09 03:23:28
【问题描述】:
我正在尝试使用 BeautifulSoup 提取链接的标题。我正在使用的代码如下:
url = "http://www.example.com"
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "lxml")
for link in soup.findAll('a', {'class': 'a-link-normal s-access-detail-page a-text-normal'}):
title = link.get('title')
print title
现在,link 元素示例包含以下内容:
<a class="a-link-normal s-access-detail-page a-text-normal" href="http://www.amazon.in/Introduction-Computation-Programming-Using-Python/dp/8120348664" title="Introduction To Computation And Programming Using Python"><h2 class="a-size-medium a-color-null s-inline s-access-title a-text-normal">Introduction To Computation And Programming Using <strong>Python</strong></h2></a>
但是,运行上述代码后,什么都没有显示。如何提取存储在link 中存储的锚标记的title 属性中的值?
【问题讨论】:
标签: python python-2.7 web-scraping beautifulsoup python-requests