Pull Data from web link to Dataframe [closed]

2024/7/7 6:18:57

I have a weblink:

url = "https://www.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=1270&symbol=RELCAPITAL&symbol=RELCAPITAL&instrument=-&date=-&segmentLink=17&symbolCount=2&segmentLink=17"

I need to move the below table data to pandas dataframe.

Data

Answer

You can use (create a helper browser):

import urllib.requestuser_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'url = "https://www.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=1270&symbol=RELCAPITAL&symbol=RELCAPITAL&instrument=-&date=-&segmentLink=17&symbolCount=2&segmentLink=17"
headers={'User-Agent':user_agent,} request=urllib.request.Request(url,None,headers)
response = urllib.request.urlopen(request)
data = response.read()

df=pd.read_html(data)[1]
print(df.head())

CALLS                                                                  \Chart     OI Chng in OI Volume     IV    LTP Net Chng BidQty BidPrice   
0   NaN      -          -      -      -      -        -  37500    32.45   
1   NaN      -          -      -      -      -        -  37500    23.90   
2   NaN      -          -      -      -      -        -  37500    15.35   
3   NaN  15000          -      -      -  24.00        -  37500     6.65   
4   NaN  46500          -      5  10.59   4.00    -8.00   1500     4.00   ...     PUTS                                                \AskPrice  ... BidPrice AskPrice AskQty Net Chng   LTP      IV Volume   
0    52.55  ...        -     1.20   3000        -     -       -      -   
1    51.75  ...        -     1.20   3000        -     -       -      -   
2    40.20  ...     1.00     1.10   1500     0.60  1.10  168.46     21   
3    20.25  ...     2.50     2.55   1500     0.60  2.00  150.32     47   
4     5.00  ...     5.35     6.00   9000     3.30  6.10  147.49    115   Chng in OI      OI Chart  
0          -       -   NaN  
1          -       -   NaN  
2     -10500  135000   NaN  
3     -22500  192000   NaN  
4     -34500  292500   NaN  [5 rows x 23 columns]
https://en.xdnf.cn/q/120067.html

Related Q&A

Python program that rolls a fair die counts the number of rolls before a 6 shows up

import randomsample_size = int(input("Enter the number of times you want me to roll the die: "))if (sample_size <=0):print("Please enter a positive number!")else:counter1 = 0coun…

How to read CSV file in Python? [duplicate]

This question already has answers here:How do I read and write CSV files?(9 answers)Closed 1 year ago.Im using Spyder for Python 2.7 on Windows 8. Im trying to open and read a csv file and see all the…

How to match the bundle id for android app?

Id like to match the urls like this:input: x = "https://play.google.com/store/apps/details?id=com.alibaba.aliexpresshd&hl=en"get_id(x)output: com.alibaba.aliexpresshdWhat is the best way…

Memory Usage During running a Deep learning CNN Model in Colab

I am conducting a research which requires me to know the memory used during run time by the model when i run a deep learning model(CNN) in google colab. Is there any code i can use to know the same .Ba…

Gensim example, TypeError:between str and int error

When running the below code. this Python 3.6, latest Gensim library in Jupyterfor model in models:print(str(model))pprint(model.docvecs.most_similar(positive=["Machine learning"], topn=20))[1…

How to interpret this JSON file?

Im trying to interpret this JSON file but I couldnt figure it out. {"results": [{"fsq_id": "4dc586fbcc3ff3b3045e2ef3","categories": [{"id": 17056,"…

How to extract a field from this payload with a regex? [duplicate]

This question already has answers here:Parse JSON with Python(2 answers)Closed 6 years ago.I have this payload that I wish to extract a field from:{"encrypted_sender_transaction_id":"514…

Python reading xml

I am newbie on Python programming. I have requirement where I need to read the xml structure and build the new soap request xml by adding namespace like here is the example what I have Below XML which …

How can sum two nested list in this situation

Given list a, b a=[[[1.1,-2.1],[-0.6,4.2]],[[3.9,1.3],[-1.3,1.2]]]b=[[-1.1,4.3],[-1.4,2.4]]If I just want to sum the list [[1.1,-2.1],[-0.6,4.2]] in the list a (not the whole list a) with the list [-1.…

Create check digit function

Im trying to create check digits and append them after the original UPCs. Heres the sample data Because there are leading 0s, I have to read the data as strings first: import pandas as pd …