【发布时间】:2017-08-04 05:57:41
【问题描述】:
正如标题所说,我正在尝试获取位于单元格内的链接的标题。 This is 我从中获取资料的网站。我还看到了this 问题,这是我最后几行代码的来源,但对我来说并没有完成
我正在尝试获取第一列(或每行的第一个单元格)内的链接标题。我可以在单元格中获取 所有 的 HTML 代码,但我无法确定仅获取标题。到目前为止,这是我想出的
URL = 'http://theescapists.gamepedia.com/Crafting'
get_page = requests.get(URL)
plain_text = get_page.text
soup = BeautifulSoup(plain_text, 'html.parser')
for table_tag in soup.find_all('table'):
for each_row in table_tag.find_all('tr'):
links = each_row.find('a', href=True)
title = links.get('title')
print(title)
print('')
如果我只打印links 部分,每个单元格中的所有代码都会被打印出来。
当我打印title 部分时,我收到一条错误消息AttributeError: 'NoneType' object has no attribute 'get',这让我很困惑,因为我已经完成了print(type(links)) and I get abs4.element.Tagback, which makes me think I should be able to look through for atitle` 标签。
作为回顾(这似乎有点长),我想从每个表中每个链接的 第一个单元格中获取标题标签
【问题讨论】:
标签: html python-3.x beautifulsoup