First, VBS parsing HTML document original address: http://www.cnblogs.com/52cik/p/vbs-parse-html.html
About VBS collection, online popular more methods are regular, in fact, Htmlfile can parse HTML code, but if DesignMode not open, sometimes package security information.
But to open the DesignMode (@ the evening of the Prophet), all JS will not be executed, just clean DOM documents, so in the case of forced to open DesignMode general situation remains the default.
SetHTML =CreateObject("Htmlfile") SetHTTP =CreateObject("msxml2.serverxmlhttp") Html.designmode=" on" 'turn on edit modeHttp.open"GET","http://www.cnblogs.com/",Falsehttp.send strhtml=http.responsetext html.write strhtml'Write DataSetPost_list = Html.getelementbyid ("post_list") for eachElinchpost_list.children WScript.Echo El.getelementsbytagname ("a")(0). InnerTextNext
In fact, the method is very simple, but the focus will be VBS, but not necessarily DOM operation, so this is very tangled.
I have no choice but to rely on your own, I just share the idea,
Parsing HTML is easier and quicker than regular.
Second, VBS parsing JSON JSONP method original address: http://www.cnblogs.com/52cik/p/vbs-parse-json.html
Yesterday said the next with Htmlfile to parse HTML, today still use him to parse, Htmlfile is a COM version of the BOM and DOM, so parsing html, execute JS completely,
Continue parsing json and JSONP today.
I've collected three common JSON JSONP formats, because a lot of people have come to me to say how to extract a string using regular, I looked at it, either JSON or JSONP,
Regular is simply wasted, such as the kind of space to say the data, hundreds of information, you are a P, but also the format of the reply is similar, so the best way is to parse.
Let's take a look at three common types:
Cool Music User Information JSON format
Http://kzone.kuwo.cn/mlog/UserVal?uid=1237357&from=profile
{"Work": 4, "fans": 275, "LP": "{\" id\ ": 1237357,\" username\ ": \" garbled \ ", \" pic\ ": \" http://img3.kuwo.cn/star/userhead/57/ 55/1315554310390_1237357m.jpg\ "}", "Art": 4, "album": 1, "Fortune": 342402, "article": 0, "Workvideo": 1, "care": 195, " Workaudio ": 3," View ": 1312997," playlist ": 0," Listen ": 278962," collect ": 1}
Clap clapping machine Query Interface JSONP format
Http://virtual.paipai.com/extinfo/GetMobileProductInfo?mobile=13012345678&amount=10000&callname=cb
CB ({mobile: ' 13012345678 ', province: ' Chongqing ', ISP: ' China Unicom ', Stock: ' 1 ', Amount: ' 10000 ', Maxprice: ' 0 ', Minprice: ' 0 '});
Sohu IP Information JS format
Http://pv.sohu.com/cityjson
var returncitysn = {"CIP": "218.72.14.14", "CID": "330100", "CNAME": "Hangzhou, Zhejiang Province"};
These kinds of appropriateness can be resolved by Htmlfile, but the methods are slightly different.
First, parse the first JSON format.
SetHTML =CreateObject("Htmlfile") SetHTTP =CreateObject("msxml2.serverxmlhttp") Http.open"GET","Http://kzone.kuwo.cn/mlog/UserVal?uid=1237357&from=profile",Falsehttp.send strhtml= Http.responsetext'Get the dataSetwindow =Html.parentwindow Window.execscript"var json ="& strHTML,"JScript" 'parsing JSONSetKUWO = Window.json'gets the parsed objectWScript.Echo"number of Visits:", Kuwo.view,"Wealth:", Kuwo.fortune
You can get the following information.
Then look at Jsonp's parsing, Jsonp is actually just a callback function, so we customize a function to parse him.
SetHTML =CreateObject("Htmlfile") SetHTTP =CreateObject("msxml2.serverxmlhttp") Callback="CB"URL="http://virtual.paipai.com/extinfo/getmobileproductinfo?mobile=13012345678&amount=10000& Callname="& callback Http.open"GET"UrlFalsehttp.send strhtml= Http.responsetext'Get the data'CB ({mobile: ' 13012345678 ', province: ' Chongqing ', ISP: ' China Unicom ', Stock: ' 1 ', Amount: ' 10000 ', Maxprice: ' 0 ', Minprice: ' 0 '});'<! --[if! ie]>|xgv00|8030d7c308afc4a32846a715ff79e9a3<! [endif]--> 'get this data, so to deal with the nextstrHTML =Split(strHTML, VBLF) (0)'take the first lineSetwindow =Html.parentwindow Window.execscript"function"& Callback &"(o) {json=o}","JScript" 'Jsonp callback function,Window.execscript strHTML,"JScript" 'parsing JSONSetJSON = Window.json'gets the parsed objectWScript.Echo Json.mobile, Json.isp, json.province
You can get the following information.
Finally look at the JS format parsing, this is the simplest, nothing to do, but you need to know his variable name.
SetHTML =CreateObject("Htmlfile") SetHTTP =CreateObject("msxml2.serverxmlhttp") Http.open"GET","Http://pv.sohu.com/cityjson",Falsehttp.send strhtml= Http.responsetext'Get the data'get var returncitysn = {"CIP": "218.72.14.14", "CID": "330100", "CNAME": "Hangzhou, Zhejiang Province"};Setwindow =Html.parentwindow window.execscript strhtml,"JScript" 'parsing JSSetJS = window.returncitysn'gets the parsed objectWScript.Echo Js.cname, Js.cip, Js.cid
You can get the following information.
JS format is the simplest, but note that the variable name is his, so you get the parsed object that step, to write his variable name.
JSON format, we just add the variable name and then parse it.
Jsonp is a bit more troublesome, because you want to write a custom callback function.
In general, the method is almost, but the parsing part is slightly different.
With Htmlfile analysis, is not more convenient than the regular?
After playing POST do not use outdated instr+mid or regular to parse the HTML JSON, Htmlfile is the kingly.
VBS DO Web collection (reprint)