python - Beautiful Soup find first <a> whose title attribute equal a certain string -


i'm working beautiful soup , trying grab first tag on page has attribute equal string.

for example:

<a href="url" title="export"></a> 

what i've been trying grab href of first found title "export".

  • if use soup.select("a[title='export']") end finding tags satisfy requirement, not first.
  • if use find("a", {"title":"export"}) conditions being set such title should equal "export", grabs actual items inside tag, not href.

  • if write .get("href") after calling find(), none back.

i've been searching documentation , stack overflow answer have yet found one. know solution this? thank you!

what i've been trying grab href of first found title "export".

you're there. need is, once you've obtained tag, you'll need index href. here's more bulletproof version:

try:     url = soup.find('a', {title : 'export' })['href']     print(url) except typeerror:     pass 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -