View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
mscir mscir is offline
Junior Member
 
Posts: 11
Default VBA to read HTML; Search for TDelement

ryguy7272 wrote:
I have code which goes to a internal corporate site, takes names from
ColumnZ in my spreadsheet, and pops them into a search box on a
company web site, searches, and returns, the results in another web
page. All of this works fine. Now, I’m trying to look through the TD
Elements on the search page, find something called SOEID, and import
the inner text (from that) into my spreadsheet, into ColumnAA. For
now, I’m testing to see if I can get the results into a MsgBox. If I
get that I can get the rest working. I noticed that TDelement.bgColor
= "#d9d9d9" will give me the SOEID, but there are a few
TDelement.bgColor = "#d9d9d9" in the page, so I have to drill down
another level…
Directly under TDelement.bgColor = "#d9d9d9 is <span
class="fineleft". This too is not unique, but under this is SOEID
and this is unique! So I want to search for that combination, and
import the inner text of the SOEID.
This is how it looks in the IE Developer Tool:
<td width="15%" bgColor="#d9d9d9"
<span class="fineleft"
Text – SOEID
<td width="15%"
<span class="fineattr"
Text - GT89111
I want to import that ‘GT89111’
Set TDelements = HTMLdoc.getElementsByTagName("TD")
For Each TDelement In TDelements
If TDelement.bgColor = "#d9d9d9" And . . . < -- problem is here . . .
Then
MsgBox (TDelement.innerText)
‘sa = TDelement.innerText
‘ With Sheets("List of FAs")
‘ .Range("AA" & CStr(RowCount)).Value =
sa
‘ End With
End If
Next
RowCount = RowCount + 1
How can I reference this:
<span class="fineleft"

Or, how can I reference this:
objCell.innerText
itm.innerText
So, any ideas on how to do this? I’m sure it is possible. I’m just
at a loss now as to how to actually do it.
Thanks everyone!


Will this approach work for you?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
<html
<head
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
<titleUntitled</title
<style type='text/css'
body{
font-family: "courier new";
}
td{
border: 1px solid green;
}
span{
border: 1px solid green;
padding: 2px 5px 2px 5px;
margin: 5px;
}
</style
<script type="text/javascript"
function doit(){
var coll_td=document.getElementsByTagName("td");
var s1;
for (n=0; n<coll_td.length; n++){
if (coll_td[n].className="fineleft"){
s1=coll_td[n].innerText;
if (s1.indexOf("SOEID") != -1) {
var coll_span= coll_td[n].getElementsByTagName("span");
alert ("span contents\n" + coll_span[0].innerText + "\n" +
coll_span[1].innerText);
break;
}
}
}
}
</script
</head
<body
<table
<tr<td<span class="fineleft"zzzzz</span<span
class="fineattr"11111</span</td</tr
<tr<td<span class="fineleft"aaaaa</span<span
class="fineattr"22222</span</td</tr
<tr<td<span class="fineleft"bbbbb</span<span
class="fineattr"33333</span</td</tr
<tr<td<span class="fineleft"SOEID</span<span
class="fineattr"44444</span</td</tr
<tr<td<span class="fineleft"ccccc</span<span
class="fineattr"55555</span</td</tr
</table
<p<input type="button" onclick="doit()" value="doit"
</body
</html