简体   繁体   English

如何使用 beautifulsoup 获取无序列表中的内容

[英]How to get content inside unordered list with beautifulsoup

The html is like this: html是这样的:

<a rel="nofollow" class="external text" href="Mylink.com"><font color="#547794"><u>My link Title</u></font></a>

I am able to extract the "a" tags but how do I extract the title "My link Title" inside the "a" tags?我能够提取“a”标签,但如何提取“a”标签内的标题“我的链接标题”?

soup = BeautifulSoup(page, 'html.parser')
for link in soup.find_all('a', href=True):
    link_str = str(link['href'])
    print(link_str)

Here is a working example这是一个工作示例

from bs4 import BeautifulSoup

html = '<a rel="nofollow" class="external text" href="Mylink.com"><font color="#547794"><u>My link Title</u></font></a>'

soup = BeautifulSoup(html.encode(), 'html.parser').find('u').text
print(soup)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM