0
感觉新浪的现在很慢,我替换成腾讯的了
def get_cur_price_tx(keys):
keys = ['sh' + i if i.startswith('60') or i.startswith('11') else 'sz' + i for i in keys ]
keys_str = ','.join(keys)
res = requests.get(url = 'http://qt.gtimg.cn/q=%s'%keys_str)
res_list = res.text.strip().split(';')
price_cur = []
price_pre_close = []
if len(keys)>0:
for i in res_list:
if len(i)==0:
continue
price = re.findall('"(.*)"',i)[0].split('~')
price_cur.append(float(price[3]))
price_pre_close.append(float(price[4]))
return price_pre_close, price_cur
def get_cur_price_tx(keys):
keys = ['sh' + i if i.startswith('60') or i.startswith('11') else 'sz' + i for i in keys ]
keys_str = ','.join(keys)
res = requests.get(url = 'http://qt.gtimg.cn/q=%s'%keys_str)
res_list = res.text.strip().split(';')
price_cur = []
price_pre_close = []
if len(keys)>0:
for i in res_list:
if len(i)==0:
continue
price = re.findall('"(.*)"',i)[0].split('~')
price_cur.append(float(price[3]))
price_pre_close.append(float(price[4]))
return price_pre_close, price_cur
0
@大掌柜
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", url, False
.Send
sTemp = .responseText
End With
替换
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", url, False
.setRequestHeader "Referer", "finance.sina.com.cn"
.Send
sTemp = .responseText
End With
Sub 市价_Click()把
Dim rowCount As Integer
Dim url As String
Dim sTemp As String
Dim sCode As String
rowCount = ActiveSheet.Range("A65535").End(xlUp).Row '获取行数
url = "http://hq.sin...
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", url, False
.Send
sTemp = .responseText
End With
替换
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", url, False
.setRequestHeader "Referer", "finance.sina.com.cn"
.Send
sTemp = .responseText
End With
0
Sub 市价_Click()
Dim rowCount As Integer
Dim url As String
Dim sTemp As String
Dim sCode As String
rowCount = ActiveSheet.Range("A65535").End(xlUp).Row '获取行数
url = "http://hq.sinajs.cn/list="
For i = 2 To rowCount
sCode = ActiveSheet.Range("B" & i).Text
If i = 2 Then
url = url & sCode
Else
url = url & "," & sCode
End If
Next i
'获取新浪股票行情数据,放入sTemp变量
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", url, False
.Send
sTemp = .responseText
End With
有没有大神用这个版本的excel行情表格?这个应该怎么修改?
Dim rowCount As Integer
Dim url As String
Dim sTemp As String
Dim sCode As String
rowCount = ActiveSheet.Range("A65535").End(xlUp).Row '获取行数
url = "http://hq.sinajs.cn/list="
For i = 2 To rowCount
sCode = ActiveSheet.Range("B" & i).Text
If i = 2 Then
url = url & sCode
Else
url = url & "," & sCode
End If
Next i
'获取新浪股票行情数据,放入sTemp变量
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", url, False
.Send
sTemp = .responseText
End With
有没有大神用这个版本的excel行情表格?这个应该怎么修改?
0
@路履薄冰
把原来的替换下面的正常,不过排序好像变了我的也是,不知道你解决了没?还有有些显示的时间不对,好像还没更新过来,是昨天的收盘价
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .response...
0
多谢,好了,主要2句
With CreateObject("WinHttp.WinHttpRequest.5.1")
.setRequestHeader "Referer", "http://finance.sina.com.cn"
@路履薄冰
With CreateObject("WinHttp.WinHttpRequest.5.1")
.setRequestHeader "Referer", "http://finance.sina.com.cn"
@路履薄冰
把原来的替换下面的正常,不过排序好像变了
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .response...
2
把原来的替换下面的正常,不过排序好像变了
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .responseText
End With
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", URL, False
.setRequestHeader "Referer", "http://finance.sina.com.cn"
.Send
sTemp = .responseText
End With
1
返回:
在代码增加了 referer 和 user-agent,顺便在 url 附带了rn 参数(时间戳+3 位随机数)。我也是刚刚修改完成,看起来正常了。
赞同来自: zhuzi51
curl --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" --referer "https://finance.sina.com.cn/stock/" -I "http://hq.sinajs.cn/?rn=1642732252985&list=sz128119,sz002726,sh113036,sh601789,sz123057,sz300586,sz128118,sz002861,sz128117,sz002838,sz127018,sz000761,sz128116,sz002961,sz123056,sz300511,sh113589,sh603608,sz128114,sz002157"
返回:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 4861
Connection: Keep-Alive
Content-Type: application/javascript; charset=GB18030
在代码增加了 referer 和 user-agent,顺便在 url 附带了rn 参数(时间戳+3 位随机数)。我也是刚刚修改完成,看起来正常了。
0
@deityz
已解决,Excel VBA代码如下:请问大侠,这段加在那个函数?每个都要加?
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
strUrl = "http://hq.sinajs.cn/list=sz163417"
xmlobject.Open "GET", strUrl, False
xmlobject.setRequestHeader "Referer", "fi...
0
python的websocket已经连接
headers = {'Referer': 'https://finance.sina.com.cn'}
ws = websocket.create_connection(url, header=headers) # 创建连接
headers = {'Referer': 'https://finance.sina.com.cn'}
ws = websocket.create_connection(url, header=headers) # 创建连接
9
赞同来自: arebu 、booboo 、被E拯救 、铁拳联队 、wangjiajie 、 、 、 、更多 »
@deityz
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
strUrl = "http://hq.sinajs.cn/list=sz163417"
xmlobject.Open "GET", strUrl, False
xmlobject.setRequestHeader "Referer", "finance.sina.com.cn"
xmlobject.send
感谢@伽南 @xxbiao
新浪接口增加了校验Referer: finance.sina.com.cn已解决,Excel VBA代码如下:
Excel的VBA怎么设置referer?求大神指点
Set xmlobject = CreateObject("WinHttp.WinHttpRequest.5.1")
strUrl = "http://hq.sinajs.cn/list=sz163417"
xmlobject.Open "GET", strUrl, False
xmlobject.setRequestHeader "Referer", "finance.sina.com.cn"
xmlobject.send
感谢@伽南 @xxbiao