搞定了,需要先执行 "pip install playwright"和 "playwright install firefox",安装必要的支持。
然后执行如下python脚本即可,数据保存在脚本所在目录下的 api_xxxx_xxxxxxxx.json文件中,我这每次执行大约不到10秒,内容如下:
from playwright.sync_api import sync_playwright
import sys
import time
import json
def record_request(request):
# print(f'{request.url=}')
if r'/sofr-strip-rates/?isProtected' in request.url:
print(f'{request.url=} {request.method=}')
response = request.response()
try:
response_dct = response.json()
except Exception as err:
print(err)
response_dct = None
print(f'response is: {response_dct}')
time_str = time.strftime("%Y%m%d_%H%M%S")
with open(f'api_{time_str}.json', 'w') as fw:
json.dump(response_dct, fw, indent=4)
with sync_playwright() as p:
app_url = "https://www.cmegroup.com/market-data/cme-group-benchmark-administration/term-sofr.html"
t1 = time.time()
print('start script now')
browser = p.firefox.launch(headless=True)
page = browser.new_page()
page.on("request", record_request)
print('goto homepage')
page.goto(app_url)
# page.wait_for_timeout(3000)
print(page.url)
print(page.title())
t2 = time.time()
print(f'runtime: {t2 - t1} s.')
--
修改:xiajusi FROM 106.120.14.*
FROM 106.120.14.*