Python - Ayuda con WEB SCRAPING de una tabla

 
Vista:
Imágen de perfil de Natixis
Val: 8
Ha disminuido su posición en 9 puestos en Python (en relación al último mes)
Gráfica de Python

Ayuda con WEB SCRAPING de una tabla

Publicado por Natixis (2 intervenciones) el 07/02/2019 00:55:00
Hola, necesito de su ayuda, estoy haciendo web scraping a una tabla y la estoy guardando en un archivo de texto, sin embargo no consigo eliminar el codigo html.

Este es mi codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import time
from tabulate import tabulate
import requests
from bs4 import BeautifulSoup
 
response = requests.get('http://www.bcra.gov.ar/PublicacionesEstadisticas/Historial-Leliq.asp')
soup = BeautifulSoup(response.text, 'html.parser')
 
titulo = soup('table', {"class": 'table table-BCRA table-bordered table-hover table-responsive'})
 
data = titulo[0].find_all('tr')
table = (tabulate(data, tablefmt='f'))
f = (open('C:\Phyton_Projects\LELIQ'+time.strftime("%Y%m%d_%H%M")+'.txt', "w"))
 
for row in table:
    f.write("%s" % row)
f.close()
print("Termina Proceso")
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 2.239
Plata
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

Ayuda con WEB SCRAPING de una tabla

Publicado por xve (1646 intervenciones) el 07/02/2019 09:01:58
Hola Natixis, para ello, puedes utilizar .get_text() para obtener solo el texto...

Te he modificado un poco el código haber si te sirve...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import time
from tabulate import tabulate
import requests
from bs4 import BeautifulSoup
 
response = requests.get('http://www.bcra.gov.ar/PublicacionesEstadisticas/Historial-Leliq.asp')
soup = BeautifulSoup(response.text, 'html.parser')
 
titulo = soup('table', {"class": 'table table-BCRA table-bordered table-hover table-responsive'})
 
data = titulo[0].find_all('tr')
table = (tabulate(data, tablefmt='f'))
f = (open('LELIQ'+time.strftime("%Y%m%d_%H%M")+'.txt', "w"))
 
for row in data:
    f.write("%s" % row.get_text().replace("\n","\t"))
f.close()
print("Termina Proceso")
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Natixis
Val: 8
Ha disminuido su posición en 9 puestos en Python (en relación al último mes)
Gráfica de Python

Ayuda con WEB SCRAPING de una tabla

Publicado por Natixis (2 intervenciones) el 07/02/2019 19:24:39
Hola:
Me sirvió perfecto, te lo agradezco mucho.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar