Jump to content
Fórum Script Brasil

Question

Bom dia.

Estou com dificuldade na raspagem de dados utilizando a biblioteca BeautifulSoup, onde a ausencia de dados dentro das <td> não é coletada. Eu gostaria de saber se existe algum parametro que devo especificar durante a busca  find_all()  ou se devo fazer um len() no conteudo pego pelo meu for lendo o tamanho do conteudo coletado na tabela e depois guardando em alguma lista

 

#!/usr/bin/python3
import pandas as pd
from bs4 import BeautifulSoup
import requests
import pandas as pd

gid = []
cidade = []
lista = pd.read_csv('/home/fabio/Downloads/Nova_lista.csv')

for i in lista['gid']:
    gid.append(i)

    for p in lista['nome']:
        cidade.append(p)
 
link = ('http://iridl.ldeo.columbia.edu/SOURCES/SOURCES/.USGS/.LandDAAC/.MODIS/.1km/.8day/.version_005/.Terra/.NSA/.Day/.LST/T/(Jan%202001)/(Mar%202015)/RANGE/X/-82/-34/RANGEEDGES/Y/-38.0/12.0/RANGEEDGES/T/monthlyAverage/home/.jdcorral/.Brazil/.mun_2016_03_21/.the_geom/gid/GID/VALUE/%5BX/Y%5Dweighted-average/T+exch+table-+text+text+skipanyNaN+-table+.html')


with open('df_temp_day.csv' , 'a') as f:


    for i in lista['gid']:

        page = requests.get(link.replace('GID','%s'%i))
        soup = BeautifulSoup(page.text,'lxml')
        tabela = soup.find_all('table',text=False)


        for td in tabela:
            linha = td.find_all('td')
            
            k = 0
            p = 1
            while k <= len(linha) and p <= len(linha):

                mes = str(linha[k].get_text())
                variavel = str(linha[p].get_text())
                k +=2
                p +=2
                n = gid.index(i)
                f.writelines('"%s", %s, "%s" ,"gid %s"\n' %(mes,variavel,cidade[n],i))
                
                print('"%s", %s, %s %s' %(mes,variavel,cidade[n],i))

 

 

Obs : Neste codigo eu já estou testando o parametro text=False, mas não sei realmente o que faz

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148894
    • Total Posts
      644914
×
×
  • Create New...