1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Text.strip() Python

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

  1. Stack

    Stack Membro Participativo

    Estou tentando fazer um código que extraia algumas informações de uma página. O Arquivo possui o seguinte formato:

    <tr class="impar">
    <td class="id">
    <a href="/judge/en/runs/code/5046623">5046623</a>
    </td>
    <td></td>
    <td class="tiny">
    <a href="/judge/en/problems/view/2173">2173</a>
    </td>
    <td class="wide">
    <a href="/judge/en/problems/view/2173">Slush Fund</a>
    </td>
    <td class="semi-wide answer a-1">
    <a href="/judge/en/runs/code/5046623">Accepted</a>
    </td>
    <td class="center">C++</td>
    <td class="tiny">0.084</td>
    <td class="center">8/27/16, 10:10:39 PM</td>
    </tr>


    Implementei o seguinte código em Python para extrair as informações: id = 2173, name = Slush Fund, language: C++. Entretanto eu recebo o seguinte erro:

    File "C:/Users/diego/Desktop/main.py", line 35, in extractProblems
    "language": td[4].text.strip()

    AttributeError: 'NoneType' object has no attribute 'text'


    Meu código:

    def extractProblems(self, soup, problems):
    itens = soup.find_all('table')[0].find_all('tbody')[0].find_all('tr')
    for tr in itens:
    td = tr.find_all('td')
    if len(td) != 8:
    return
    else:
    problems[td[1].find('a').text.strip()] = {
    "id_code": td[2].find('a').text.strip(),
    "name": td[3].find('a').text.strip(),
    "language": td[4].text.strip()
    }


    Alguém poderia me ajudar?

    Continue reading...

Compartilhe esta Página