简体   繁体   中英

How to get content inside unordered list with beautifulsoup

The html is like this:

<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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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