Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web Browser Inner Text 1

Status
Not open for further replies.

Error7

Programmer
Jul 5, 2002
656
GB
I am trying to read this source which is displayed when I right click on the webpage and click View Source.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/main.css" rel="stylesheet" type="text/css">
<link href="/main_new.css" rel="stylesheet" type="text/css">
<title>3/7B M61 QW17-MS3 - K SPUR</title>
<script>

function updateImage(){
document.images['camImage'].src = "/cctvpublicaccess/images/35237.jpg?sid=" + Math.random();
}

</script>
</head>
<body style="background-color: rgb(225,238,246);" onload="updateImage();">
<img src="" name='camImage' id='camImage' style='position: relative; top: 0;left:0;'></img>
<div align="center" style='position: relative;'><b>Camera: 35237 - 3/7B M61 QW17-MS3 - K SPUR</b> &nbsp&nbsp&nbsp&nbsp <a href="#" onclick="updateImage();" title="Images are refreshed every 30 seconds">Refresh</a></div>
<div align="center" style='position: relative;'><b>The carriageway closest to the camera is Southbound</b></div>
</body>
</html>

I have tried:

WB1.Document.documentElement.innerHTMl
WB1.Document.documentElement.OuterHTML
WB1.Document.Body.InnerText

None of which display the source as displayed above. Can somebody please point me in the right direction with this.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Have you tried WB1.Document.Body.OuterHTML?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Hi Andy, I hadn't tried that previously but I have now and that doesn't give the required source either.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Try referencing different values for:

WB1.Document.all.item(x).outerhtml

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Thanks for trying Andy. Unfortunately that didn't work either.

I need the information contained in between the bold tags in the body text i.e. <b>Camera: 35237 - 3/7B M61 QW17-MS3 - K SPUR</b> but I haven't yet figured out a way to get to see the body text that is shown when you right click on the page.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Try navigating to the bit of the URL after the = sign.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Good suggestion Andy. That idea does work but only if I first connect using the full URL i.e. then while still connected connect again with:
That will probably do as a workaround.
Thanks a million.


[gray]Experience is something you don't get until just after you need it.[/gray]
 
Hmm yes I'm actually surprised that there isn't a document property for getting the same source that you get when you right-click the WB and do View Source, hopefully someone else can be more helpful.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Thanks for your help anyway. It got me off the ground.

I'm wrapping up now. Approaching 21:00 here and it's time to eat.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
@Error7
[0] it depends on how determined you want to get the source (as view-source would display). Within the application, the simplest is to use the msxml2.xmlhttp to get the responsetext. Doing it synchonously will result in simpler code; doing it asynchronously will be (much) more involved coding-wise.

[1] You can do like this within some click event-handler for viewsource purpose, say. (Adding appropriate reference on msxml2.xmlhttp60 with version changed, if needed; or more with nostalgic/veteran-feel, you can do the same with winhttp.winhttprequest)

[1.1]
[tt]
'add the approrpiate reference
Dim xmlhttp As New MSXML2.XMLHTTP60
'Dim xmlhttp As New WinHttp.WinHttpRequest

'suppose the webbrowser1 be your webbrowser control
'and it has loaded with something already
xmlhttp.open "get", WebBrowser1.LocationURL, False
xmlhttp.send

Dim s As String
s = xmlhttp.responseText 'this is your view-source result
'Suppose you have a textbox (Text1) with appropriate multiline, scrollbars settings
'at design time for viewing pleasure, you can display it simply like this:
'Text1.text=s
[/tt]
[1.2] That's about it.
 
Thanks tsuji for you code. I tried it but unfortunately it just gives the same source as my first attempt.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Hi!

1.) Add a reference to MS HTML library
2.)
Code:
Dim objMSHTML As HTMLDocument, src As HTMLDocument
Dim SCode as String
Set objMSHTML = New MSHTML.HTMLDocument

Set src = objMSHTML.createDocumentFromUrl([urltonavigateto])
While src.readyState <> "complete"
     DoEvents
Wend
[b]Scode = src.all.toString[/b]
...
This should give you the source code.
;-)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I'm getting 'Argument not optional' in:
.createDocumentFromUrl([urltonavigateto])

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Yes, you need to put something like:
.createDocumentFromUrl("
- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Ooops! Sorry, missed something:
Code:
.createDocumentFromUrl("[URL unfurl="true"]http://www.mysite.com"[/URL][b],vbNullString[/b])
[blush]
Sorry!

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Well that eliminated the error, thanks, but Scode only returns [object]

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Yes, I played around a bit and it seems that the "toString" method does not deliver a meaningful string.

So instead of further educated guesses, I tried, and this gives a promising output:

Code:
Dim objMSHTML As HTMLDocument, src As HTMLDocument
Dim SCode As String
Set objMSHTML = New MSHTML.HTMLDocument

Set src = objMSHTML.createDocumentFromUrl("[URL unfurl="true"]http://www.tek-tips.com",[/URL] vbNullString)
While src.readyState <> "complete"
     DoEvents
Wend
SCode = [b]src.getElementsByTagName("HTML")(0).outerHTML[/b]

;-)

Cheers,
MakeItSo

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Thanks for your efforts MakeItSo, unfortunately your code now returns:

<HTML xmlns=" Camera</TITLE></HEAD>
<BODY style="BACKGROUND-COLOR: #e1eef6" onload=javascript:self.focus()>
<FORM id=form1 action=trafficcamera.aspx?cameraUri=http%3a%2f%2fpublic.hanet.org.uk%2fcctvpublicaccess%2fhtml%2f39153.html method=post>
<DIV><INPUT id=__VIEWSTATE type=hidden value=/wEPDwUKMTYyNzcxNDY4Ng9kFgICAw9kFgICAQ8WAh4EVGV4dAU7aHR0cDovL3B1YmxpYy5oYW5ldC5vcmcudWsvY2N0dnB1YmxpY2FjY2Vzcy9odG1sLzM5MTUzLmh0bWxkZM6iC4HdN3oExGZSrK6dUci2A1WA name=__VIEWSTATE> </DIV>
<DIV><IFRAME src=" width=372 scrolling=no height=325>
</div>
</form>
</body>
</html></IFRAME></DIV></FORM></BODY></HTML>

which isn't the same source that is displayed if I right click on the webpage and view source.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top