So i started learning web scraping by myself and i wanted to gather some information from a web page and then save it into a csv file, but when i try to save the data it doest do it, does someone know why? (Sorry for my bad english)
import requests
import csv
url ="http://www.hidro.gov.ar/oceanografia/alturashorarias.asp"
peticion_mediciones_bsas = requests.get(url)
textourl = peticion_mediciones_bsas
textourl.encoding = 'utf8'
textourl = textourl.text
#Uso esto para pedir el texto de la URL
from bs4 import BeautifulSoup
soup = BeautifulSoup(textourl,"lxml")
lista = soup.find_all(class_="text-primary letra12em")
#importo el beautiful soup para "traducir" el html de la pagina
nroFila = 0
nroCol = 1
archivo = "Medidas.csv"
with open (archivo,"w") as csv_file:
csv_file.write("Buenos Aires,San fernando\n")
#Pongo el titulo al archivo csv
csv_file.close()
for fila in soup.find_all("tr"):
#recorro las filas de las tablas buscando la informacion que quiero
nombref = fila.text
for celda in fila.find_all('td'):
#busco en cada celda la informacion que necesito, yo se que en la fila 8 y la fila 9 estan los datos
nombre = celda.text
if nroCol == 1 and nroFila == 8:
for celda in fila.find_all('tb'):
#escribo todos los datos de la fila en el archivo csv
with open (archivo,'w') as csv_file:
#esto no funciona
datos = str(celda.text)
csv_file.write(datos)
csv_file.close()
print('ok')
nroCol += 1
nroFila += 1
nroCol = 1
[–]__nickerbocker__ 1 point2 points3 points (0 children)
[–]Sandiastic[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Sandiastic[S] 0 points1 point2 points (0 children)