使用 Excel VBA 将焦点设置到 IE PDF 样式网页以进行抓取
Setting focus to an IE PDF style webpage for scraping using Excel VBA
我浏览了这个受密码保护的网站并到达了一个点,它打开了一个看起来像 child window 但有一个 URL 像 "http://yadayadayada**.pdf**?V42"
的地方。
虽然它是 PDF,但我可以手动点击它到 select 并复制数据。
我的问题是通过代码将焦点设置到它。
我已经尝试了多种循环遍历打开页面的 URL 的变体,但它无法识别,我无法将焦点设置到这个页面。
如果一切都失败了,我可以将它保存为 PDF,通过 Adobe 打开它并从那里抓取它。
我不确定我是否真的明白你想要什么。下面的代码测试每个打开的应用程序是否是 Internet Explorer,如果是,它是否具有正确的 url 作为位置。更多信息在评论中。
重要提示:无需激活选项卡即可从中抓取数据。我也不知道如何在 IE 中将选项卡置于前台。不知何故没人知道 ;-)
Sub ScrapeFromTabs()
Dim allShell As Object
Dim oneWindow As Object
Set allShell = CreateObject("Shell.Application")
'Go through all open windows
'Each tab in IE is treated as a window by the OS.
For Each oneWindow In allShell.Windows
'Check if it is a window of the Internet Explorer
If InStr(1, UCase(oneWindow.FullName), "IEXPLORE") > 0 Then
'Check whether the relevant parts are present in the URL
If InStr(1, oneWindow.locationURL, "yadayadayada") > 0 And InStr(1, oneWindow.locationURL, ".pdf") > 0 Then
'Do here what you want with the pdf
'Whatever is possible with a pdf ... somthing like this
'set nodeHeadline = oneWindow.getElementsByTagName("h1")(0)
'It was the right tab with the pdf
'Leave the loop
Exit For
End If
End If
Next oneWindow
End Sub
我浏览了这个受密码保护的网站并到达了一个点,它打开了一个看起来像 child window 但有一个 URL 像 "http://yadayadayada**.pdf**?V42"
的地方。
虽然它是 PDF,但我可以手动点击它到 select 并复制数据。
我的问题是通过代码将焦点设置到它。
我已经尝试了多种循环遍历打开页面的 URL 的变体,但它无法识别,我无法将焦点设置到这个页面。
如果一切都失败了,我可以将它保存为 PDF,通过 Adobe 打开它并从那里抓取它。
我不确定我是否真的明白你想要什么。下面的代码测试每个打开的应用程序是否是 Internet Explorer,如果是,它是否具有正确的 url 作为位置。更多信息在评论中。
重要提示:无需激活选项卡即可从中抓取数据。我也不知道如何在 IE 中将选项卡置于前台。不知何故没人知道 ;-)
Sub ScrapeFromTabs()
Dim allShell As Object
Dim oneWindow As Object
Set allShell = CreateObject("Shell.Application")
'Go through all open windows
'Each tab in IE is treated as a window by the OS.
For Each oneWindow In allShell.Windows
'Check if it is a window of the Internet Explorer
If InStr(1, UCase(oneWindow.FullName), "IEXPLORE") > 0 Then
'Check whether the relevant parts are present in the URL
If InStr(1, oneWindow.locationURL, "yadayadayada") > 0 And InStr(1, oneWindow.locationURL, ".pdf") > 0 Then
'Do here what you want with the pdf
'Whatever is possible with a pdf ... somthing like this
'set nodeHeadline = oneWindow.getElementsByTagName("h1")(0)
'It was the right tab with the pdf
'Leave the loop
Exit For
End If
End If
Next oneWindow
End Sub