0
@老好a人
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .responseText
End With
splits = Split(sTemp, ";")
For jj = 1 To maxCountPer
ii = kk * maxCountPer + jj + 1
If ii <= rowCount Then
mystr = splits(jj - 1)
ss = InStr(mystr, ",")
If ss > 1 Then
startindex = InStr(1, mystr, """")
endindex = InStrRev(mystr, """")
substr = Mid(mystr, startindex + 1, endindex - 1)
valuearray = Split(substr, ",")
begin = Asc("B")
J = 0
sheet.Range(Chr(begin + J) & ii).Value = valuearray(0) 'Ãû³Æ
J = J + 1
If valuearray(3) = 0 Then
不会呀,请求时间设置长一点。再暂停50毫秒请问怎么设置呢,我下面这个代码在最后一句发现经常取到值是空的,十次有两三次取不到值
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .responseText
End With
splits = Split(sTemp, ";")
For jj = 1 To maxCountPer
ii = kk * maxCountPer + jj + 1
If ii <= rowCount Then
mystr = splits(jj - 1)
ss = InStr(mystr, ",")
If ss > 1 Then
startindex = InStr(1, mystr, """")
endindex = InStrRev(mystr, """")
substr = Mid(mystr, startindex + 1, endindex - 1)
valuearray = Split(substr, ",")
begin = Asc("B")
J = 0
sheet.Range(Chr(begin + J) & ii).Value = valuearray(0) 'Ãû³Æ
J = J + 1
If valuearray(3) = 0 Then
7
赞同来自: 趋势交易者 、mainidea 、youyong 、睡哥1 、zhuzi51 、 、更多 »
顺便怕死的(比如我)可以把新浪腾讯网易三个接口都做了,出问题能实时热备切换
http://qt.gtimg.cn/q=sh600000
http://api.money.126.net/data/feed/0600000
具体用法度娘都有
http://qt.gtimg.cn/q=sh600000
http://api.money.126.net/data/feed/0600000
具体用法度娘都有
0
多谢各位大佬指点,附上c#代码
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://hq.sinajs.cn/list=sh600000");
request.Referer = "http://vip.stock.finance.sina.com.cn/"; // 多加这句,其他和原来一样
StreamReader streamReader = new StreamReader(((HttpWebResponse)request.GetResponse()).GetResponseStream(), Encoding.Default);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://hq.sinajs.cn/list=sh600000");
request.Referer = "http://vip.stock.finance.sina.com.cn/"; // 多加这句,其他和原来一样
StreamReader streamReader = new StreamReader(((HttpWebResponse)request.GetResponse()).GetResponseStream(), Encoding.Default);
0
业余python玩家,用的req_one = urllib.request.Request(url)
请求头这样写
req_one.add_header('User-Agent', 'Mozilla/6.0')
req_one.add_header('Referer', 'http://vip.stock.finance.sina.com.cn/')
请求头这样写
req_one.add_header('User-Agent', 'Mozilla/6.0')
req_one.add_header('Referer', 'http://vip.stock.finance.sina.com.cn/')
参考https://app.jisilu.cn/question/449479
1
赞同来自: whfxjc
Excel vba代码:
Function GetHttp(Url)
Dim xmlobject
On Error Resume Next
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
xmlobject.Open "GET", Url, False
xmlobject.setRequestHeader "Referer", "http://vip.stock.finance.sina.com.cn/"
xmlobject.send
GetHttp = xmlobject.ResponseBody
GetHttp = BytesToBstr(GetHttp, "GB2312")
Set objXML = Nothing
On Error GoTo 0
End Function
Function GetHttp(Url)
Dim xmlobject
On Error Resume Next
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
xmlobject.Open "GET", Url, False
xmlobject.setRequestHeader "Referer", "http://vip.stock.finance.sina.com.cn/"
xmlobject.send
GetHttp = xmlobject.ResponseBody
GetHttp = BytesToBstr(GetHttp, "GB2312")
Set objXML = Nothing
On Error GoTo 0
End Function
0
我也可以用了,谢谢各位大神。还有没搞明白的没得。就是在请求头哪里,多家一项
strcat(buf,"Referer: 加网址\r\n");
C++语言就可以了
send(socket,buf,strlen(buf),0);
strcat(buf,"Referer: 加网址\r\n");
C++语言就可以了
send(socket,buf,strlen(buf),0);
0
@Leo3155
增加Header:感谢大神,按照您的代码改好了.
Referer: http://vip.stock.finance.sina.com.cn/
'获取新浪股票行情数据,放入sTemp变量
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Re...
0
@zj2117719
Function GetHttp(Url)显示股票价格还是之前原来的 getstock=(sh'')吗
' Dim objXML
' On Error Resume Next
' Set objXML = CreateObject("Microsoft.XMLHTTP")
' With objXML
' .Open "Get", Url, False, "", ""
' .Send
' Ge...
0
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", Url, False, "", ""
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .responseText
End With
.Open "GET", Url, False, "", ""
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .responseText
End With
3
赞同来自: asd555asd 、hzy7413 、流沙少帅
python:
headers = {
"Accept-Encoding": "gzip, deflate, sdch",
"Referer":"http://vip.stock.finance.sina.com.cn/",
"User-Agent": (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/54.0.2840.100 "
"Safari/537.36"
),
}
headers = {
"Accept-Encoding": "gzip, deflate, sdch",
"Referer":"http://vip.stock.finance.sina.com.cn/",
"User-Agent": (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/54.0.2840.100 "
"Safari/537.36"
),
}
0
@Leo3155
增加Header:好使了,谢谢
Referer: http://vip.stock.finance.sina.com.cn/
'获取新浪股票行情数据,放入sTemp变量
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Re...
4
Function GetHttp(Url)
' Dim objXML
' On Error Resume Next
' Set objXML = CreateObject("Microsoft.XMLHTTP")
' With objXML
' .Open "Get", Url, False, "", ""
' .Send
' GetHttp = .ResponseBody
' End With
' GetHttp = BytesToBstr(GetHttp, "GB2312")
' Set objXML = Nothing
' On Error GoTo 0
'------------------------------------------------------------
Dim xmlobject
On Error Resume Next
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
xmlobject.Open "GET", Url, False
xmlobject.setRequestHeader "Referer", "finance.sina.com.cn"
xmlobject.send
GetHttp = xmlobject.ResponseBody
GetHttp = BytesToBstr(GetHttp, "GB2312")
Set objXML = Nothing
On Error GoTo 0
'------------------------------------------------------------
End Function
注解的是原先的模块,适用于excel VBA 感谢@deityz
' Dim objXML
' On Error Resume Next
' Set objXML = CreateObject("Microsoft.XMLHTTP")
' With objXML
' .Open "Get", Url, False, "", ""
' .Send
' GetHttp = .ResponseBody
' End With
' GetHttp = BytesToBstr(GetHttp, "GB2312")
' Set objXML = Nothing
' On Error GoTo 0
'------------------------------------------------------------
Dim xmlobject
On Error Resume Next
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
xmlobject.Open "GET", Url, False
xmlobject.setRequestHeader "Referer", "finance.sina.com.cn"
xmlobject.send
GetHttp = xmlobject.ResponseBody
GetHttp = BytesToBstr(GetHttp, "GB2312")
Set objXML = Nothing
On Error GoTo 0
'------------------------------------------------------------
End Function
注解的是原先的模块,适用于excel VBA 感谢@deityz
11
赞同来自: saul2020 、shenzuiwen 、lianyx2000 、牛肉干 、hzy7413 、 、 、 、 、 、更多 »
增加Header:
Referer: http://vip.stock.finance.sina.com.cn/
'获取新浪股票行情数据,放入sTemp变量
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://vip.stock.finance.sina.com.cn/"
.Send
sTemp = .responseText
End With
splits = Split(sTemp, ";")
Referer: http://vip.stock.finance.sina.com.cn/
'获取新浪股票行情数据,放入sTemp变量
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://vip.stock.finance.sina.com.cn/"
.Send
sTemp = .responseText
End With
splits = Split(sTemp, ";")
0
同求问,应该怎么改
'取新浪行情
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", URL, False
.Send
sTemp = .responseText
End With
splits = Split(sTemp, ";")
For jj = 1 To maxCountPer
ii = kk * maxCountPer + jj + 1
If ii <= rowCount Then
mystr = splits(jj - 1)
下面这个mystr就变成了"Kinsoku jikou desu!" ,不再是原来的行情字符串
'取新浪行情
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", URL, False
.Send
sTemp = .responseText
End With
splits = Split(sTemp, ";")
For jj = 1 To maxCountPer
ii = kk * maxCountPer + jj + 1
If ii <= rowCount Then
mystr = splits(jj - 1)
下面这个mystr就变成了"Kinsoku jikou desu!" ,不再是原来的行情字符串
0
Set HttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
HttpReq.Open "get", uri, False
HttpReq.setRequestHeader "Accept", "*/*"
HttpReq.setRequestHeader "Accept -Encoding", "gzip , deflate"
HttpReq.setRequestHeader "Accept -Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"
HttpReq.setRequestHeader "Connection", "keep -alive"
HttpReq.setRequestHeader "Host", "hq.sinajs.cn"
HttpReq.setRequestHeader "Referer", "http://finance.sina.com.cn/realstock/company/sh000001/nc.shtml"
HttpReq.setRequestHeader "User -Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0"
HttpReq.Send
mystr = HttpReq.responseText
这样不行啊
HttpReq.Open "get", uri, False
HttpReq.setRequestHeader "Accept", "*/*"
HttpReq.setRequestHeader "Accept -Encoding", "gzip , deflate"
HttpReq.setRequestHeader "Accept -Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"
HttpReq.setRequestHeader "Connection", "keep -alive"
HttpReq.setRequestHeader "Host", "hq.sinajs.cn"
HttpReq.setRequestHeader "Referer", "http://finance.sina.com.cn/realstock/company/sh000001/nc.shtml"
HttpReq.setRequestHeader "User -Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0"
HttpReq.Send
mystr = HttpReq.responseText
这样不行啊