[Python] Web scraping table from UniProt database

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I have a list of UniProt IDs and would like to use BeautifulSoup to scrap a table containing the structure information. The url I am using is as follows: https://www.uniprot.org/uniprot/P03496, with accession "P03496".

    A snippet of the html code is as follows.

    <div class="main-aside">
    <div class="content entry_view_content up_entry swissprot">
    <div class="section" id="structure">
    <protvista-uniprot-structure accession="P03468">
    <div class="protvista-uniprot-structure">
    <div class="class=" protvista-uniprot-structure__table">
    <protvista-datatable class="feature">
    <table>...</table>
    </protvista-datatable>
    </div>
    </div>
    </protvista-uniprot-structure>
    </div>
    </div>
    </div>


    The information I require is contained between the <table>...</table> tag.

    I tried

    from bs4 import BeautifulSoup
    import requests

    url='https://www.uniprot.org/uniprot/P03468'
    r=requests.get(url)
    url=r.content
    soup = BeautifulSoup(url,'html.parser')
    soup.find("protvista-datatable", {"class": "feature"})
    print(soup)

    Continue reading...

Compartilhe esta Página