如何使用 xmlhttp 检索 onClick/onChange 数据
我对这一切还比较陌生,寻找这个问题的答案一直让我很痛苦。请注意,我可能问了错误的问题,甚至可能提出了错误的术语,但就其价值而言:
作为站点用户,我尝试使用 VBA 中的 xmlhttp 对象“导航”内部 aspx 站点。虽然我可以通过使用明显的 URL 行来访问某些网站页面上的 elementID,但某些 ElementID 是动态生成的,因此直到用户从菜单中进行选择之后才可用。该信息是通过某种 onChange/onClick/javascript/postback 函数加载的。有没有办法检索这些动态信息?此外,这是否是正确的方法?
注意:我可以使用 IE 对象来完成所有这些操作,但出于性能原因我确实试图避免它。
经过文档检查,网页端代码显示:
<select name="ctl00$plcContent$Item1$Tabs$tabServices$Services$ddServiceCats" onchange="javascript:setTimeout('__doPostBack(\'ctl00$plcContent$Item1$Tabs$tabServices$Services$ddServiceCats\',\'\')', 0)" id="ctl00_plcContent_Item1_Tabs_tabServices_Services_ddServiceCats">
<option selected="selected" value="00000000-0000-0000-0000-000000000000">Select Service Category</option>
<option value="3f44517e-135a-466a-8440-9b1250d5285b">Kites</option>
<option value="7ec669b7-4d2c-4216-b19e-491faa13995a">Bikes</option>
<option value="f0bb692f-3df7-4c04-80d4-7e2b4a2805c3">Tikes</option>
.
.
.
我用来访问网页的 VBA 如下:
With xml
.Open "GET", BASE_URL3, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send ([no idea what to write here for the purposes of this question])
End With
目标是识别在之后加载的“自行车”子类别(例如,“轮胎”)的 elementID我们弄清楚如何“选择”主类别(子类别的 elementID 值是动态的)。
如果我需要发布更多代码,请告诉我。
再次感谢您的帮助。
I'm relatively new at all this, and the search to answer this question has been killing me. Note that I may be asking the wrong question, and maybe even the wrong terminology, but for what it's worth:
As a site user, I'm trying to "navigate" through an internal aspx site using the xmlhttp object in VBA. While I'm able to access elementID's on certain site pages by using obvious URL lines, certain ElementID are dynamically generated, and thus unavailable until after, for example, the user makes a selection from a menu. The info is loaded as a result of some sort of onChange/onClick/javascript/postback function. Is there a way to retrieve this dynamic information? Furthermore, is this even the right approach?
Note: I can do all this using the IE object, but I'm really trying to avoid it for performance reasons.
Upon document inspection, the webpage side code shows:
<select name="ctl00$plcContent$Item1$Tabs$tabServices$Services$ddServiceCats" onchange="javascript:setTimeout('__doPostBack(\'ctl00$plcContent$Item1$Tabs$tabServices$Services$ddServiceCats\',\'\')', 0)" id="ctl00_plcContent_Item1_Tabs_tabServices_Services_ddServiceCats">
<option selected="selected" value="00000000-0000-0000-0000-000000000000">Select Service Category</option>
<option value="3f44517e-135a-466a-8440-9b1250d5285b">Kites</option>
<option value="7ec669b7-4d2c-4216-b19e-491faa13995a">Bikes</option>
<option value="f0bb692f-3df7-4c04-80d4-7e2b4a2805c3">Tikes</option>
.
.
.
The VBA I'm using to access the webpage is below:
With xml
.Open "GET", BASE_URL3, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send ([no idea what to write here for the purposes of this question])
End With
The goal is to identify the elementID of a subcategory of "Bikes" (for instance, like 'tires') that gets loaded after we figure out how to "select" a main category (the subcategory's elementID value is dynamic).
Please let me know if I need to post more code.
Thanks again for you help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信你的问题的根源在于难以区分客户端使用 JavaScript 发生的事情与服务器端执行的事情(我假设是 VBA)。
当您谈论“站点”时,您也混合了隐喻,而我认为您指的是页面,并且对页面上的 URL 和 HTML 元素感到困惑。
老实说,我不完全理解您所描述的内容以及您想要做什么。
直接回答您的问题:是的,您可以检索通过 xmlhttp 请求从服务器发送的动态信息。希望您使用框架在客户端执行该请求,并且 xmlhttp 请求中的回调方法将包含来自服务器的数据有效负载(响应)。如果不查看正在执行的代码,就很难为您提供详细的指导。
如果由于某种原因您无法访问 AJAX 请求的回调方法,您还可以内省结果页面的 DOM 结构,但您再次需要知道您要查找的内容(即结果更新了哪些元素) )。
发布一些男女同校的文章,也许我们可以帮助您。
I believe the root of your problem lies in difficulty separating what happens on the client side with JavaScript vs. what gets executed on the server side (VBA I assume).
You are also mixing your metaphors when you talk about "site" when I think you mean a Page as well as confused about URLs and HTML elements on the Page.
To be honest I don't fully understand what you are describing and what you are trying to do.
To answer your question directly: yes you can retrieve dynamic information that gets sent from the server via an xmlhttp request. Hopefully you are using a framework to execute that request on the client side and the callback method from your xmlhttp request will contain the data payload (response) from the server. Without looking at the code that is being executed its difficult to give you detailed direction.
If for some reason you do not have access to the callback method of your AJAX request you can also introspect the DOM structure of the resultant page but you again need to know what you are looking for (i.e. which element/s were updated as a result).
Post some coed and perhaps we can help you along.