Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA关闭IE javascript弹出窗口_Vba_Excel_Web Scraping - Fatal编程技术网

VBA关闭IE javascript弹出窗口

VBA关闭IE javascript弹出窗口,vba,excel,web-scraping,Vba,Excel,Web Scraping,下面的代码打开InternetExplorer的一个实例并下载。它工作正常,但偶尔会出现一个弹出窗口,导致代码无法工作。当弹出窗口出现时,有关于如何导航以下弹出窗口(即单击“继续到oddschecker”)的帮助吗 <a class="continue beta-callout js-close-class" onclick='s_objectID="javascript:void(0)_9";return this.s_oc?this.s_oc(e):true' href="javasc

下面的代码打开InternetExplorer的一个实例并下载。它工作正常,但偶尔会出现一个弹出窗口,导致代码无法工作。当弹出窗口出现时,有关于如何导航以下弹出窗口(即单击“继续到oddschecker”)的帮助吗

<a class="continue beta-callout js-close-class" onclick='s_objectID="javascript:void(0)_9";return this.s_oc?this.s_oc(e):true' href="javascript:void(0)">Continue to Oddschecker</a>

完整代码:

Sub Oddschecker()

Dim ie, wp As Object
Dim i As Integer

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.Navigate "https://www.oddschecker.com/horse-racing/racing-coupon"

Do While ie.Busy
    DoEvents
Loop

Do While ie.ReadyState <> 4
    DoEvents
Loop

Set wp = ie.Document

'Application.ActiveSheet.UsedRange.ClearContents
Application.Worksheets("sheet1").UsedRange.ClearContents

i = 2
For Each rw In wp.getElementsByTagName("table")(0).getElementsByTagName("tr")
    If rw.className = "date" Then
        Worksheets("sheet1").Range("A1") = rw.innerText
    ElseIf rw.className = "fixture-name" Then
        i = i + 1
        Worksheets("sheet1").Range("A" & i) = rw.getElementsByTagName("td")(0).innerText
        i = i + 1
    ElseIf rw.className = "coupons-table-row match-on" Then
        For Each od In rw.getElementsByTagName("p")
            If InStr(od.innerText, "(") <> 0 Then
                Worksheets("sheet1").Range("A" & i) = Trim(Left(od.innerText, InStr(od.innerText, "(") - 1))
                np = Trim(Right(od.innerText, Len(od.innerText) - InStr(od.innerText, "(")))
                Worksheets("sheet1").Range("B" & i) = Left(np, Len(np) - 1)
                i = i + 1
            Else
                Worksheets("sheet1").Range("A" & i) = Trim(od.innerText)
                i = i + 1
            End If
        Next od

    End If
Next rw

ie.Quit

Range("A1:B" & i).WrapText = False
Columns("A:B").EntireColumn.AutoFit

Set wp = Nothing
Set ie = Nothing


End Sub
Sub-Oddschecker()
模糊ie,可湿性粉剂作为对象
作为整数的Dim i
设置ie=CreateObject(“InternetExplorer.Application”)
可见=假
即“导航”https://www.oddschecker.com/horse-racing/racing-coupon"
忙着干吧
多芬特
环
请稍等,即ReadyState 4
多芬特
环
设置wp=ie.Document
'Application.ActiveSheet.UsedRange.ClearContents
应用程序。工作表(“表1”)。UsedRange.ClearContents
i=2
对于wp.getElementsByTagName(“表”)(0.getElementsByTagName(“tr”)中的每个rw
如果rw.className=“日期”,则
工作表(“表1”).范围(“A1”)=rw.innerText
ElseIf rw.className=“夹具名称”然后
i=i+1
工作表(“sheet1”).Range(“A”和i)=rw.getElementsByTagName(“td”)(0).innerText
i=i+1
ElseIf rw.className=“优惠券表行匹配”然后
对于rw.getElementsByTagName(“p”)中的每个od
如果InStr(od.innerText,“(”)0,则
工作表(“表1”)。范围(“A”和i)=修剪(左侧(od.innerText,仪表(od.innerText,“(”)-1))
np=修剪(右侧(外径innerText,Len(外径innerText)-InStr(外径innerText,“(”))
工作表(“表1”)。范围(“B”和i)=左侧(np,Len(np)-1)
i=i+1
其他的
工作表(“表1”).范围(“A”和i)=修剪(od.innerText)
i=i+1
如果结束
下一个od
如果结束
下一个rw
即退出
范围(“A1:B”和i)。WrapText=False
列(“A:B”).entireclumn.AutoFit
设置wp=Nothing
设置ie=无
端接头

如果您希望继续使用该页面(导航到该弹出页面),可以尝试以下操作:

Dim HTML As HTMLDocument, addcheck As Object

While IE.Busy = True Or IE.readyState < 4: DoEvents: Wend ''(You can write it the way you feel comfortable)
Set HTML = IE.document  ''place this line after the prevous line

Set addcheck = HTML.querySelector("#promo-modal a.continue")
If Not addcheck Is Nothing Then
    addcheck.Click
End If
Dim HTML作为HTMLDocument,addcheck作为对象
当IE.Busy=True或IE.readyState<4:DoEvents:Wend''时(您可以用自己感觉舒服的方式编写)
Set HTML=IE.document''将此行放在前一行之后
Set addcheck=HTML.querySelector(#promo modal a.continue)
如果没有,那么addcheck什么都不是
添加检查。单击
如果结束
但是,这不是一个好主意,因为它会将您引导到某个页面,在该页面中,您可能需要执行一些活动才能回到这个充满数据的页面

我想你应该通过点击右上角的交叉按钮来摆脱弹出窗口拦截器,然后继续做你正在做的事情:

Dim HTML As HTMLDocument, addcheck As Object

While IE.Busy = True Or IE.readyState < 4: DoEvents: Wend ''(You can write it the way you feel comfortable)
Set HTML = IE.document  ''place this line after the prevous line

Set addcheck = HTML.querySelector("#promo-modal span[title='Close")
If Not addcheck Is Nothing Then
    addcheck.Click
End If
Dim HTML作为HTMLDocument,addcheck作为对象
当IE.Busy=True或IE.readyState<4:DoEvents:Wend''时(您可以用自己感觉舒服的方式编写)
Set HTML=IE.document''将此行放在前一行之后
Set addcheck=HTML.querySelector(“促销模式span[title='Close”)
如果没有,那么addcheck什么都不是
添加检查。单击
如果结束

如果我不明白你的意图,一定要告诉我。谢谢。

也许是一个线索。谢谢@ashleedawg。我添加了以下内容,看起来很有希望:
ie.Navigate“javascript:u doPostBack('ctl00$LinkButton1','')
所以没有确定的方法来重现这一点?此外,如果您确实找到了解决方案,请记住发布它。谢谢Sim。关闭弹出窗口是理想的解决方案(因为弹出窗口可能会改变)但这两个选项都会重定向回数据页。选项1:当我添加子项时,它似乎崩溃了,我在子项的何处提交?对于选项2,我在运行子项时(在HTML部分)会出错。我的另一个问题是,pop并不总是出现,这可能是子系统崩溃的原因。您是指我在上面粘贴的子系统还是您正在使用的子系统?如果您是指我的子系统,我找不到导致其崩溃的任何原因。
addcheck。单击
If block
中,并且应该仅处于激活状态当它找到
popupblocker
时,它会被激活。很抱歉没有解释清楚。我的意思是,我在我的sub中应该把你提供的sub称为哪里?链接它似乎是我遇到问题的地方。谢谢。现在,我已经编辑了我的帖子,使它可以在你的脚本中使用。你可以放置你喜欢的(我更喜欢第二个)在你的脚本中,就在这一行之前,你的脚本因为弹出窗口阻止程序而崩溃。谢谢你的更新。我没有启用HTML对象库,这导致了一个问题。我正在通宵运行代码,如果所有代码都成功运行,明天将进行更新。