macro - can you scrape an xml file and then use it to fill a web form?

岁酱吖の 提交于 2020-01-17 07:24:45

问题


I have a program that generates xml files. I need to use the xml data to fill out a form on a website. (and then use a loop to do this multiple times). From the research I've done so far, it sounds like the way to do this is to have imacros open the xml file in the browser, then scrape the data, then open the web form and fill it out.

Now, how does all that fit into one script? Can one script both read data and then use it to fill out a form?

I also looked into autohotkey but it seemed a lot more complicated than imacros - does anyone have an opinion on what is more suitable for this task?

I would appreciate if anyone can point me in the right direction here. Thanks!

(in case anyone asks, I thought about skipping the form and using curl to post the data, but it turned out to be way too complicated. it's a government site, using servlets to validate information, and i gave up on that.)


回答1:


Perhaps this example of how to scrape XML data under 'iMacros for Firefox' will be helpful to you:

URL GOTO=http://www.xmlfiles.com/examples/simple.xml
SEARCH SOURCE=REGEXP:"([\\s\\S]*)" EXTRACT=$1
PROMPT {{!EXTRACT}}

Anyway I believe that you should apply the JavaScript Scripting Interface in order to accomplish successfully this task.




回答2:


AutoHotkey is a fine choice for this task. More specifically you want to use COM Objects to access your XML data and Internet Explorer COM Objects to paste information to your website.

XML COM Example:

exampleXML := 
(
"<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>"
)    

doc := ComObjCreate("MSXML2.DOMDocument.6.0")
doc.async := false
doc.loadXML(exampleXML)


MsgBox % doc.selectSingleNode("//from").text "`n"
        . doc.selectSingleNode("//body").text

IE COM Example:

pwb := ComObjCreate("InternetExplorer.Application") 
pwb.Visible := True 
pwb.RegisterAsBrowser := true 
pwb.Navigate("www.w3schools.com/html/html_forms.asp") 
    While pwb.Busy
        Continue
Sleep 3000
pwb.document.getElementsByClassname("w3-white w3-padding notranslate")[0]
.getElementsByTagname("input")[0].innertext := "Daffy"
pwb.document.getElementsByClassname("w3-white w3-padding notranslate")[0]
.getElementsByTagname("input")[1].innertext := "Duck"
MsgBox % "Ok to exit"
PWB.Quit()


来源:https://stackoverflow.com/questions/41713229/macro-can-you-scrape-an-xml-file-and-then-use-it-to-fill-a-web-form

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