问题
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