• some text
  • som...">
    All geek questions in one place

    BeautifulSoup cannot find a tag by class

    Here is the part of the web page:

    <div class="MPinfo"> <ul class="frontList"> <li>some text</li> <li>some text</li> <li>some text</li> <li>some text</li> <li>some text</li> <li>some text <a href="/some_local_link/8976">some text</a>; <a href="/some_local_link/8943">some text</a>; </li> <li>E-mail: <a href="mailto: Ss.Sssssss@mail.com "> Ss.Sssssss@mail.com </a> </li> </ul> </div> 

    I am trying to get a div by its class and then extract the link by email only for sending by email, for example: Ss.Sssssss@mail.com

     page = urllib.urlopen(link) soup = BeautifulSoup(page.read()) print soup.find('div', attrs={'class': 'MPinfo'}) 

    I tried several ways to get a div, but it returns an empty list or None

    +5
    python beautifulsoup
    Victor Nikolov Mar 30 '16 at 14:35
    source share
    1 answer

    You can select all li under the div, it will be a list, so you can select the last li element, for example [-1]

     >>> soup.find("div",attrs={"class":"MPinfo"}).find_all("li")[-1].a.text ' Ss.Sssssss@mail.com ' 
    0
    sinanerdinc Feb 28 '18 at 15:10
    source share

    Source: https://habr.com/ru/post/1246079/

    More articles:

    • How to compile boost with GCC 5 using old ABI? - gcc
    • Why is my program resource intensive even though I set THREAD_MODE_BACKGROUND_BEGIN? - c ++
    • Phoenix Rendering 404 and 500 as JSON - elixir
    • Newtonsoft.Json serializes multiple elements twice - json.net
    • Javascript date does not look right when month changes - javascript
    • What is the difference between initializing with = and initializing with {}? - c ++
    • Add custom URL to Google Apps for work - google-apps
    • Postgres - ON CONFLICT - HOW to know if an UPDATE has occurred instead of an INSERT - sql
    • Windows packet forwarding - network-programming
    • Vertical TextView with Ellipsize and all other default TextView features - android

    All Articles

    Geek Questions | 2019