通过下面的链接下载了一个csv文件。我无法将其用作pandas Dataframe
这里的标题必须复制粘贴从红框所附的图像作为网站不支持一般的要求。
this is the NSE website .
this is the Dev Tools from where the headers has to be copied
import requests
import pandas as pd
import csv
header = ''''''
def header_in_dictionary(header):
unwanted = '''sec-ch-ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin'''
header = header.replace(unwanted,'')
header_list = header.split('\n')
key_list = ['accept','accept-encoding','accept-language','cookie','referer','user-agent','x-requested-with']
value_list = []
for ele in header_list:
if ':' in ele:
value_list.append(ele[ele.index(':') + 2:len(ele)])
else:
None
header_dictionary = {}
index_counter = 0
for ele in key_list :
header_dictionary[ele] = value_list[index_counter]
index_counter += 1
return header_dictionary
aa = requests.get("https://www.nseindia.com/api/historical/cm/equity?symbol=ASIANPAINT&series=[%22EQ%22]&from=01-04-2021&to=9-03-2023&csv=true", headers = header_in_dictionary(header))
我想使用csv文件的数据。为此,我必须将其转换为pandas Dataframe 。
1条答案
按热度按时间6uxekuva1#
使用
requests.Session
,因为您需要存储cookie:输出: