Created
January 22, 2015 00:37
-
-
Save n8henrie/08a31f02fd1282d12b75 to your computer and use it in GitHub Desktop.
Prompts for a URL, displays HTML tables from that page, then converts the selected table to a csv file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
"""html_to_csv.py | |
Prompts for a URL, displays HTML tables from that page, then converts | |
the selected table to a csv file. | |
""" | |
import sys | |
import pandas | |
url = input("Enter the URL: ") | |
tables = pandas.io.html.read_html(url) | |
for index, table in enumerate(tables): | |
print("Table {}:".format(index + 1)) | |
print(table.head() + '\n') | |
print('-' * 60) | |
print('\n') | |
choice = int(input("Enter the number of the table you want: ")) - 1 | |
filename = input("Enter a filename (.csv extension assumed): ") + '.csv' | |
with open(filename, 'w') as outfile: | |
tables[choice].to_csv(outfile, index=False, header=False) |
Are you sure you're copying the code correctly? Looks like you're missing the 4 spaces.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. Why I keep gettinn an error
File "./file.py", line 14
print("Table {}:".format(index + 1))
^
IndentationError: expected an indented block