cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lala
Level VIII

如何将这些内容加入JSL、实现用JSL下载数据?

有个网址是POST方式的数据、

我已经用Chrome分析了它的URL、并按"Copy as cURL (bash)"复制了

2021-08-19_180106.png

请教专家:

如何将这些写入JSL中、才能下载这个网址的数据?

非常感谢!

 

1 ACCEPTED SOLUTION

Accepted Solutions
stan_koprowski
Community Manager Community Manager

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

Hi @lala,

You can do something like the following using the information provided--

Names Default To Here( 1 );
stock_n = "002466";
page = "1";
stock_page_str = "&stockno=" || stock_n || "&pageIndex=" || page;
base_url = "https://www.wlstock.com/ajaxRequrst/StockFundFlowAjax.ashx?act=3";
url = base_url || stock_page_str; 

stock_request = New HTTP Request(
	URL( url ),
	Method( "POST" ),
	Headers(
		{"Content-Type, application/x-www-form-urlencoded; charset=UTF-8"},
		{"Origin, https://www.wlstock.com"},
		{"Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7"},
		{"Sec-Fetch-Site", "same-origin"},
		{"Cookie",
		"__utmz=1.1629363027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); HWWAFSESID=5c23e883e2470897bb; HWWAFSESTIME=1629383287343; Hm_lvt_16ae844519b6d6a721828d6914c625ff=1629366513,1629367214,1629369083,1629383289; Hm_lpvt_16ae844519b6d6a721828d6914c625ff=1629383289; __utma=1.1098944855.1629363027.1629369083.1629383289.3; __utmc=1; __utmt=1; __utmb=1.2.10.1629383289"
		},
		{"Accept-Encoding", "gzip, deflate, br"},
		{"Referer",
		"https://www.wlstock.com/hudong/stockfundflow.aspx?stockno=002466"},
		{"User-Agent",
		"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
		},
		{"X-Requested-With", "XMLHttpRequest"},
		{"Sec-Fetch-Mode", "cors"},
		{"Accept: application/json, text/javascript, */*; q=0.01"}
	)
);

json = stock_request << Send;
If( stock_request << Is Success,
	dt = JSON To Data Table( json );
	dt << Set Name( "Stock_Number_" || stock_n );
);

cheers,

Stan

View solution in original post

8 REPLIES 8
lala
Level VIII

回复: 如何将这些内容加入JSL、实现用JSL下载数据?

复制所得到的内容

curl 'https://www.wlstock.com/ajaxRequrst/StockFundFlowAjax.ashx?act=3' -H 'Connection: keep-alive' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Origin: https://www.wlstock.com' -H 'X-Requested-With: XMLHttpRequest' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-Mode: cors' -H 'Referer: https://www.wlstock.com/hudong/stockfundflow.aspx?stockno=002466' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7' -H 'Cookie: __utma=1.1098944855.1629363027.1629363027.1629363027.1; __utmz=1.1629363027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); HWWAFSESID=4cf4679b97f4a3e6d6; HWWAFSESTIME=1629366513360; Hm_lvt_16ae844519b6d6a721828d6914c625ff=1629363027,1629363561,1629364787,1629366513; Hm_lpvt_16ae844519b6d6a721828d6914c625ff=1629366513; __utmc=1; __utmt=1; __utmb=1.30.10.1629363027' --data 'stockNo=002466&pageIndex=2' --compressed

这个是JSON的方式

{
    "data":"stockNo=002466&pageIndex=2",
    "method":"POST",
    "url":"https://www.wlstock.com/ajaxRequrst/StockFundFlowAjax.ashx?act=3",
    "headers":{
        "Accept":" application/json, text/javascript, */*; q=0.01",
        "Accept-Encoding":" gzip, deflate, br",
        "Accept-Language":" zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7",
        "Connection":" keep-alive",
        "Content-Type":" application/x-www-form-urlencoded; charset=UTF-8",
        "Cookie":" __utma=1.1098944855.1629363027.1629363027.1629363027.1; __utmz=1.1629363027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); HWWAFSESID=4cf4679b97f4a3e6d6; HWWAFSESTIME=1629366513360; Hm_lvt_16ae844519b6d6a721828d6914c625ff=1629363027,1629363561,1629364787,1629366513; Hm_lpvt_16ae844519b6d6a721828d6914c625ff=1629366513; __utmc=1; __utmt=1; __utmb=1.30.10.1629363027",
        "Origin":" https://www.wlstock.com",
        "Referer":" https://www.wlstock.com/hudong/stockfundflow.aspx?stockno=002466",
        "Sec-Fetch-Mode":" cors",
        "Sec-Fetch-Site":" same-origin",
        "User-Agent":" Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
        "X-Requested-With":" XMLHttpRequest"
    }
}

 

 

python的方式

import requests

headers = {
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Origin': 'https://www.wlstock.com',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
    'Sec-Fetch-Site': 'same-origin',
    'Cookie': '__utma=1.1098944855.1629363027.1629363027.1629363027.1; __utmz=1.1629363027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); HWWAFSESID=4cf4679b97f4a3e6d6; HWWAFSESTIME=1629366513360; Hm_lvt_16ae844519b6d6a721828d6914c625ff=1629363027,1629363561,1629364787,1629366513; Hm_lpvt_16ae844519b6d6a721828d6914c625ff=1629366513; __utmc=1; __utmt=1; __utmb=1.30.10.1629363027',
    'Accept-Encoding': 'gzip, deflate, br',
    'Referer': 'https://www.wlstock.com/hudong/stockfundflow.aspx?stockno=002466',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'Sec-Fetch-Mode': 'cors',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
}

data = 'stockNo=002466&pageIndex=2'

response = requests.post('https://www.wlstock.com/ajaxRequrst/StockFundFlowAjax.ashx?act=3', headers=headers, data=data)

 

ih
Super User (Alumni) ih
Super User (Alumni)

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

Hi lala,

 

Have a look at the function New HTTP Request.  More info can be found here Re: Importing Web Service Data: The New HTTP Request in JMP® 14 ( US 2018 231 ) 

 

Note that if you have existing python code that works you can call that directly using functions like Python Send()

lala
Level VIII

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

谢谢!

这个帖子我也学习过。我对于 POST的处理方法还是没有掌握。

 

未能找到解决方法。

lala
Level VIII

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

excel、VBA

Sub http_request()
    Dim winhttpObj As Object
    Dim resp as String
    Set winhttpObj = CreateObject("WinHttp.WinHttpRequest.5.1")
    With winhttpObj
    .Open "POST", "https://www.wlstock.com/ajaxRequrst/StockFundFlowAjax.ashx?act=3", False
    .setRequestHeader "Connection", "keep-alive"
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
        .setRequestHeader "Origin", "https://www.wlstock.com"
        .setRequestHeader "Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7"
        .setRequestHeader "Sec-Fetch-Site", "same-origin"
        .setRequestHeader "Cookie", "__utmz=1.1629363027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); HWWAFSESID=5c23e883e2470897bb; HWWAFSESTIME=1629383287343; Hm_lvt_16ae844519b6d6a721828d6914c625ff=1629366513,1629367214,1629369083,1629383289; Hm_lpvt_16ae844519b6d6a721828d6914c625ff=1629383289; __utma=1.1098944855.1629363027.1629369083.1629383289.3; __utmc=1; __utmt=1; __utmb=1.2.10.1629383289"
        .setRequestHeader "Accept-Encoding", "gzip, deflate, br"
        .setRequestHeader "Referer", "https://www.wlstock.com/hudong/stockfundflow.aspx?stockno=002466"
        .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
        .setRequestHeader "X-Requested-With", "XMLHttpRequest"
        .setRequestHeader "Sec-Fetch-Mode", "cors"
        .setRequestHeader "Accept", "application/json, text/javascript, */*; q=0.01"
	.Send "stockNo=002466&pageIndex=1"
    End With
    resp = winhttpObj.responsetext
End Sub
stan_koprowski
Community Manager Community Manager

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

Hi @lala,

You can do something like the following using the information provided--

Names Default To Here( 1 );
stock_n = "002466";
page = "1";
stock_page_str = "&stockno=" || stock_n || "&pageIndex=" || page;
base_url = "https://www.wlstock.com/ajaxRequrst/StockFundFlowAjax.ashx?act=3";
url = base_url || stock_page_str; 

stock_request = New HTTP Request(
	URL( url ),
	Method( "POST" ),
	Headers(
		{"Content-Type, application/x-www-form-urlencoded; charset=UTF-8"},
		{"Origin, https://www.wlstock.com"},
		{"Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7"},
		{"Sec-Fetch-Site", "same-origin"},
		{"Cookie",
		"__utmz=1.1629363027.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); HWWAFSESID=5c23e883e2470897bb; HWWAFSESTIME=1629383287343; Hm_lvt_16ae844519b6d6a721828d6914c625ff=1629366513,1629367214,1629369083,1629383289; Hm_lpvt_16ae844519b6d6a721828d6914c625ff=1629383289; __utma=1.1098944855.1629363027.1629369083.1629383289.3; __utmc=1; __utmt=1; __utmb=1.2.10.1629383289"
		},
		{"Accept-Encoding", "gzip, deflate, br"},
		{"Referer",
		"https://www.wlstock.com/hudong/stockfundflow.aspx?stockno=002466"},
		{"User-Agent",
		"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
		},
		{"X-Requested-With", "XMLHttpRequest"},
		{"Sec-Fetch-Mode", "cors"},
		{"Accept: application/json, text/javascript, */*; q=0.01"}
	)
);

json = stock_request << Send;
If( stock_request << Is Success,
	dt = JSON To Data Table( json );
	dt << Set Name( "Stock_Number_" || stock_n );
);

cheers,

Stan

lala
Level VIII

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

非常感谢!

lala
Level VIII

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

看来POST的变化较多的。

2021-08-20_154225.png

另一网址的数据POST结构有不同、用同样的分析不能下载。

 

我参考了社区的帖子、按stan的代码修改

query ="pxpageIndex=1&pageSize=50&clIndex=0&dlIndex=0";
base_url = "https://www.wlstock.com/ShuJu/StockFundFlowQuery.aspx";
url = base_url ; 

stock_request = New HTTP Request(
	URL( url ),
	Method( "POST" ),

	QueryString( query )
);

可以下载数据、但JSON结构问题、得到的数据每行数据是重复多次的。

 

lwx228
Level VIII

Re: 如何将这些内容加入JSL、实现用JSL下载数据?

cheers,

stock_request = New HTTP Request(
	URL( url ),
	Method( "POST" ),
);