How do you extract data from vendor website in vbscript?

﹥>﹥吖頭↗ 提交于 2019-12-12 03:09:01

问题


I have programmed a post image HTA which is launched after an XP image has been loaded onto a computer. The HTA gathers information from the user (ie primary user name, department, etc) and updates the registry under a custom key. Management has asked if I can pull the computer's warranty information (specifically the warranty end date) from the vendor's website (in this case Lenovo) and update the registry with this info. Lenovo allows anonymous lookup using computer type and serial number and returns a page showing warranty information. Is there a way using vbscript (or maybe javascript?) to parse the returned page for the data I'm looking for?

Thanks in advance, Gill


回答1:


Using an HTML parser would probably be a more robust way to do this, but it's easy with VBScript to just script Internet Explorer through OLE Automation.

Dim ie, frm

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www-307.ibm.com/pc/support/site.wss/" & _
    "document.do?lndocid=LOOK-WARNTY#sw"
Do Until ie.ReadyState = 4 '' READYSTATE_COMPLETE
    WScript.Sleep 100
Loop

Set frm = ie.Document.Forms.warrantyLookup
frm.type.Value = "2644"
frm.serial.Value = "23AB123"
frm.Submit

Do Until ie.Document.ReadyState = "complete"
    WScript.Sleep 100
Loop

'' Locate the information you want to scrape from the
'' ie.Document DOM at this point

ie.Quit



回答2:


You can scrape the page that is returned fairly easily, all it really takes is an HTML parser, and then knowledge of where the information you want is located within the returned page. I do not know of any VBScript HTML parsers, but I am sure they exist. If you cannot find one, however, you can call out to an external program from locally running code, so you could write a page scraping utility in any number of languages (or use some sort of grep utility), and that may do what you are looking for.



来源:https://stackoverflow.com/questions/2067379/how-do-you-extract-data-from-vendor-website-in-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!