[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
想爬一个网站的资料 用python可以做出来 但是用R就发生问题
google不到解决方式
求板上高手帮忙
谢谢
[程式范例]:
<python> 可以顺利跑出来
import requests
import pandas as pd
import json
url = "https://securev.jihsun.com.tw/JssFHCTradeNet/JSStockCR/
StockRatingCR_P.aspx/GetData"
headers = {'Content-Type': 'application/json; charset=UTF-8'}
data = {'stockNo': '2330'}
response = requests.post(url = url, data=json.dumps(data), headers=headers)
<R>
url = "https://securev.jihsun.com.tw/JssFHCTradeNet/JSStockCR/
StockRatingCR_P.aspx/GetData"
headers = c('Content-Type' = 'application/json; charset=UTF-8')
data = '{"stockNo": "2330"}'
get_data <- httr::POST(url = url,
httr::add_headers(.headers=headers),
body = data)
# 会喷出下面的error
# Error in curl::curl_fetch_memory(url, handle = handle) :
# Maximum (10) redirects followed
[环境]
R version 4.0.4
curl 4.3
httr 1.4.2
macbbok M1
[关键字]: