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

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

Ansible warning on jinja2 braces on when -

html - How to custom Bootstrap grid height? -