[問題] 爬蟲POST問題

作者: ppp1987 (ppp)   2021-04-01 23:50:29
[問題類型]:
程式諮詢(我想用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
[關鍵字]:

Links booklink

Contact Us: admin [ a t ] ucptt.com