2

I have been trying to import a html table from a website and to convert it into a pandas DataFrame. This is my code:

import pandas as pd
table = pd.read_html("http://www.sharesansar.com/c/today-share-price.html")
dfs = pd.DataFrame(data = table)
print dfs 

It just displays this:

0       S.No                                     ...

But if I do;

for df in dfs:
    print df

It outputs the table..

How can I use pd.Dataframe to scrape the table?

1 Answer 1

5

HTML table on the given url is javascript rendered. pd.read_html() doesn't supports javascript rendered pages. You can try with dryscrape like so:

import pandas as pd
import dryscrape

s = dryscrape.Session()
s.visit("http://www.sharesansar.com/c/today-share-price.html")
df = pd.read_html(s.body())[5]
df.head()

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.