Sina Stock Real-time Data hq.sinajs.cn Interface Fix
Sina Stock Real-time Data hq.sinajs.cn Interface Repair
Sina stock real-time data hq.sinajs.cn suddenly became inaccessible and couldn’t fetch data. This is because Sina stock has blocked the interface. You can get data by adding a forged header domain in the original data collection interface.
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, https://finance.sina.com.cn ); //referer
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $uri);
$response = curl_exec($ch);
if (curl_errno($ch)) {
//$errno = curl_error($ch);
curl_close($ch);
//return [‘errno’ = $errno];
return false;
} else {
curl_close($ch);
return $response;
}
*******************
The commonly used Sina real-time stock data interface, http://hq.sinajs.cn/list=code, has recently been updated. Direct access via web page returns “Kinsoku jikou desu!” (Japanese for “Access denied,” quite cultural!)
After investigation, it was found that HTTPS must be used, and a Referer field must be added to the request header.
Since I previously used @持有封基 teacher’s Excel template, the related VBS code needs to be updated to add request headers. However, the original XmlHttp object cannot forge some HTTP header information (including Referer), so it must be changed to WinHttp object to access.
Here is the modified macro code:
With CreateObject(“WinHttp.WinHttpRequest.5.1”)
.Open “GET”, URL, False
.setRequestHeader “Referer”, “https://finance.sina.com.cn”
.Send
sTemp = .responseText
End With
-
Alipay QR Code Scan
-
WeChat Scan Pay