使用excel VBA点击网站的按钮

编程入门 行业动态 更新时间:2024-10-23 23:21:47
本文介绍了使用excel VBA点击网站的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个我正在写的脚本,我可以通过宏在网站上执行一个表单。我可以打开互联网浏览器,并正确传递所有的变量,但是当它提交的时候,我有点迷失了。

这是网站上的元素我想点击 - 它是一个标题为购买的按钮

< input type =submitname =submit值= 购买 >

我有两个问题:

1 )我不知道如何正确地引用这个在vba 2)它旁边有一个按钮,将执行一个卖(完全相反的我想做的),其元素是:

< input type =submitname =submitvalue =Sell>有没有人知道适当的代码来点击购买按钮?

这是我的代码到目前为止:

Dim IE As Object Set IE = New InternetExplorer IE.Visible = True IE.Navigatesomewebsite 尽管IE.Busy:DoEvents:Loop 尽管IE.ReadyState< > 4:DoEvents:Loop IE.Document.All(resourceoption)。Value =item IE.Document.All(amount)。Value = 1 IE.Document .All(priceper)。值= 99 Do While IE.Busy:DoEvents:Loop Do While IE.ReadyState<> 4:DoEvents:Loop

解决方案

与IE.document 设置elems = .getElementsByTagName(input)对于每个e在elems 如果(e.getAttribute(value )=Buy)然后 e.Click 退出结束如果 下一步e 结束

上述代码段执行所需的任务

I have a script I am writing where I can execute a form on a website through a macro. I am able to open up internet explorer and pass all the variables correctly however when it comes time to submit, I am a bit lost.

this is the element on the website i want to click - it is a button titled "buy"

<input type="submit" name="submit" value="Buy">

I have two problems:

1) i don't know how to properly reference this within vba 2) there is a button right next to it that will perform a sell (the exact opposite of what i want to do) and the element for that is:

<input type="submit" name="submit" value="Sell">

Does anyone know appropriate code to hit the 'buy' button?

here is my code thus far:

Dim IE As Object Set IE = New InternetExplorer IE.Visible = True IE.Navigate "somewebsite" Do While IE.Busy: DoEvents: Loop Do While IE.ReadyState <> 4: DoEvents: Loop IE.Document.All("resourceoption").Value = "item" IE.Document.All("amount").Value = 1 IE.Document.All("priceper").Value = 99 Do While IE.Busy: DoEvents: Loop Do While IE.ReadyState <> 4: DoEvents: Loop

解决方案

With IE.document Set elems = .getElementsByTagName("input") For Each e In elems If (e.getAttribute("value") = "Buy") Then e.Click Exit For End If Next e End With

the above snippet performs the task needed

更多推荐

使用excel VBA点击网站的按钮

本文发布于:2023-06-09 04:12:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/594982.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   网站   excel   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!