【发布时间】:2021-07-15 09:33:32
【问题描述】:
我正在尝试将网页中的 JSON 导入数据框,这是我第一次尝试这样做,但我不明白我做错了什么。我想从 calendarEntries 中获取一个包含两列的数据框:productCode、settlement
import requests
import pandas as pd
import os
os.chdir('D:/')
def scrape(url):
session = requests.Session()
session.headers.update(
{'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0'})
time.sleep(rd.randint(0, 10))
response = session.get(url, params={"_": int(time.time() * 1000)})
return response
def main():
option_url = f'https://www.cmegroup.com/CmeWS/mvc/ProductCalendar/Options/138'
response = scrape(option_url)
expiration=pd.read_json(response)
print(expiration)
if __name__ == "__main__":
main()
【问题讨论】:
-
您能否解释一下您的代码出了什么问题,如果您遇到错误,请在问题中添加错误消息
标签: python json pandas dataframe