To the point:
I have successfully used VBA to do the following:
Important to note - The website is client-side
The above was the simple part, the difficult part is as below:
clicking on a gif image within the iframe that exports the dataset to a csv
I have tried the following:
Dim idoc As HTMLDocument
Dim iframe As HTMLFrameElement
Dim iframe2 As HTMLDocument
Set idoc = objIE.document
Set iframe = idoc.all("iframename")
Set iframe2 = iframe.contentDocument
Do Until InStr(1, objIE.document.all("iframename").contentDocument.innerHTML, "img.gif", vbTextCompare) = 0
DoEvents
Loop
To give some context to the logic above -
- I accessed the main frame
- i accessed the iframe by its name element
- i accessed the content within the iframe
- I attempted to find the gif image that needs to be clicked to export to csv
It is at this line that it trips up saying "Object doesn't support this property or method"
Also tried accessing the iframe gif by the a element and href attribute but this totally failed. I also tried grabbing the image from its source URL but all this does it take me to the page the image is from.
note: the iframe does not have an ID and strangely the gif image does not have an "onclick" element/event
Final consideration - attempted scraping the iframe using R
accessing the HTML node of the iframe was simple, however trying to access the attributes of the iframe and subsequently the nodes of the table proved unsuccessful. All it returned was "Character(0)"
library(rvest)
library(magrittr)
Blah <-read_html("web address redacted") %>%
html_nodes("#iframe")%>%
html_nodes("#img")%>%
html_attr("#src")%>%
#read_html()%>%
head()
Blah
As soon as a i include read_html the following error returns on the script:
Error in if (grepl("<|>", x)) { : argument is of length zero
I suspect this is referring to the Character(0)
Appreciate any guidance here!
Many Thanks,
HTML
<div align="center">
<table id="table1" style="border-collapse: collapse" width="700" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td colspan="6"> </td>
</tr>
<tr>
<td colspan="6">
<a href="href redacted">
<img src="img.gif" width="38" height="38" border="0" align="right">
</a>
<strong>x - </strong>
</td>
</tr>
</tbody>
</table>
</div>
Question&Answers:
os