0

I would like to get the value from the title attribute, i.e. "xxx". How can I fetch it?

<p>blabla <span class="ticker-hover-wrapper">(xyz:<a href="examplelink" title="xxx" target="_blank">text</a>)```

My current code looks like this:
``` name = webpage.find('a', target="_blank").a.text['title']
                    print (name)
                    name = " ".join(name)
                    name_data.append(name)```

Any ideas?
bencolo
  • 31
  • 2
  • Does this answer your question? [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) – MendelG Jul 01 '21 at 14:09

1 Answers1

1

Using beautifulsoup4 you can use this:

from bs4 import BeautifulSoup

soup = BeautifulSoup("html", "lxml")
element = soup.find("a", {"target": "_blank"})
print("The element points to", element["href"])
HostedPosted
  • 88
  • 1
  • 4