marconso
(usa XUbuntu)
Enviado em 23/08/2017 - 12:03h
Boa tarde galera... Nao estou conseguindo coletar a ausencia de dados dentro de umas <td> no meu programa
to usando beautifulsoup
segue o codigo
#!/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',text=False)
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))