VBA code fails to load a valid URL link, Why?

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

Why would ie/Firefox fail to load a web page?
The following code runs in my WinXP SP3/Word2000.
From ie/Firefox the main site loads for me as a user, and has a link "sitemap" which functions correctly when I click on it.
When I try to follow the link using Word2000/VBA (in an otherwise successful application), I get a 404 error.
Caveat: I am not a web/html guru, but over the years I've been able to dabble in html. This may turn out to be a case of "A little knowledge is a dangerous thing".
I had previously been using Excel 2000's Web Query to achieve my objectives, but the ie object seems much neater and faster.

Code: Select all

Sub QuickTest()
    ''' From "http://www.winaltainc.com/" the link SiteMap returns "http://www.winaltainc.com/sitemap/"
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        ''' Following results in (ie 8, Firefox 3.5.1) "Sorry, we can't find the page you're looking for"
        .Navigate "http://www.winaltainc.com/sitemap/"
        Do Until .ReadyState = 4
            DoEvents
        Loop
    End With
End Sub
An expensive day out: Wallet and Grimace

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA code fails to load a valid URL link, Why?

Post by StuartR »

Chris,

If I paste the url http://www.winaltainc.com/sitemap/" onclick="window.open(this.href);return false; into the address bar in Firefox 3.6 or IE8 then it gives me an error 404.
StuartR


User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA code fails to load a valid URL link, Why?

Post by HansV »

I also get the 404 error if I enter http://www.winaltainc.com/sitemap" onclick="window.open(this.href);return false; in the address bar of my browser and press Enter, so it's not the code. The Site Map page is loaded some other way.
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA code fails to load a valid URL link, Why?

Post by StuartR »

HansV wrote:...it's not the code. The Site Map page is loaded some other way.
I also get the 404 error if I click the Site Map link on the home page. So it might just be a page that has got lost.
StuartR


User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA code fails to load a valid URL link, Why?

Post by HansV »

I can see the sitemap:
sitemap.JPG
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
mwolfman
The Man, The Myth, The Legend
Posts: 770
Joined: 16 Jan 2010, 00:14
Location: New Jersey

Re: VBA code fails to load a valid URL link, Why?

Post by mwolfman »

Chris - what is the file name in the sitemap/ directory? index.htm .html .php?
Mike Wolfman

--To err is human; to really screw up requires root

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

StuartR wrote:If I paste the url ... into the address bar in Firefox 3.6 or IE8 then it gives me an error 404.
(First of many responses)
Stuart, thanks for this.
If you r/c on the link for "Sitemap" and copy/paste into Notepad, you'll get this: "http://www.winaltainc.com/sitemap/".
If you then copy/paste that link into the browser you get the 404, right?

What I don't understand is why a pasted link will not function as well as a clickable link.
When I View page Source I see toggling comments and code "// toggles the slickbox on clicking the noted link" and the like.
I suspect that there is some clever dynamic stuff going on that allows the host site to interpret the link rather than using it just as a regular static link.

(signed) "Out of my depth" of Toronto.
An expensive day out: Wallet and Grimace

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

HansV wrote:... so it's not the code.
Thanks Hans. I assume by this you mean "It's not Chris's (stolen) VBA code".
Excepting that, of course, I'll have to work out a way around it.
An expensive day out: Wallet and Grimace

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA code fails to load a valid URL link, Why?

Post by StuartR »

Interestinger and interestinger!

I can see the site map IF I ENABLE winaltainc.com in NoScript.

If you view the page source you will see that the site map link runs the following javascript code

Code: Select all

...
	<div id="sm_outer">
		<div id="sm_inner">
		<!--winalta sitemap-->
	
	<a id="sm_toggle_close" href="/sitemap/">
	<div id="close">
		<span style="position: relative; left: 15px;">close</span>
	</div>
	</a>	
...

StuartR


User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

StuartR wrote:I also get the 404 error if I click the Site Map link on the home page. So it might just be a page that has got lost.
Thanks again Stuart.
I don't think the site map is lost. As Hans pointed out with his screen-shot, the site map is there.
I've tried various combinations trying to trip it up, but everything functions normally for me as an end-user.
I used the "X" Close button on the site map to close it; I toggled it away by clicking on Site map (this after I'd seen the Toggle code in the web page source).
Out of keen passionate interest, and please, what browser are you using that generates the 404 when you click on site map?
An expensive day out: Wallet and Grimace

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA code fails to load a valid URL link, Why?

Post by StuartR »

ChrisGreaves wrote:...Out of keen passionate interest, and please, what browser are you using that generates the 404 when you click on site map?
See answer above. The Site Map menu item runs javascript code, which you can't do from your control I don't think.
StuartR


User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

StuartR wrote:I can see the site map IF I ENABLE winaltainc.com in NoScript.
Aaaaaaaaaaargh, said "Out-of-my-depth" in Toronto.
Please, what/where is NoScript? Is it a Tools, Options in your browser, and if so what?
FWIW I have JavaScript enabled in my Firefox 3.5.1. (doesn't everyone???)
If I disable it, the Sitemap link fails to work; but when re-enable it, the site map bounces up and down twice (four motions) like a Canadian watching Sidney Crosby score another goal.
With JavaScript enabled and Java disabled the sitemap dis/appears as it should.

All of this as an end-user, not running my VBA code.
An expensive day out: Wallet and Grimace

User avatar
mwolfman
The Man, The Myth, The Legend
Posts: 770
Joined: 16 Jan 2010, 00:14
Location: New Jersey

Re: VBA code fails to load a valid URL link, Why?

Post by mwolfman »

The site is in php which means it is dynamically makes the html. The only reason I can see the link will not come up in the browsers is:

The java is calling a specific file and its not called index.html, .htm .php. Do you have a directory list of sitemap/?
Mike Wolfman

--To err is human; to really screw up requires root

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA code fails to load a valid URL link, Why?

Post by StuartR »

ChrisGreaves wrote:...Please, what/where is NoScript?
...
NoScript is a Firefox add on, that lets you enable and disable Javescript on a site by site basis (as well as protecting you against other assorted nasties.
StuartR


User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

mwolfman wrote:The java is calling a specific file and its not called index.html, .htm .php. Do you have a directory list of sitemap/?
Mike, thanks for getting involved (he said, struggling to keep his head above water)
I think I am beginning to see some light.

My little application (of which a fragment is posted here) is supposed to locate each web page referenced from a given web page. That is, for some URL of a client of mine, load that page, then attempt to load each link on that page. Report Errors.
My assumption was that excepting for obvious links (ending in .JPG, .ZIP etc.) I would be looking at htm/html links, and that they would load if the web pages were present, and would not load (Report Error!) if they were not present.

I had not contemplated public web sites that build web pages on-the-fly in this manner.
I can read the body text returned (this SiteMap page shows me "Sorry, we can't find the page you're looking for") and detect in VBA that *I* have had a problem.

I can trace back the problem "20100301113957 URLer ChrisL strPageFound - Page Not Found FROM http://www.winaltainc.com/sitemap/" onclick="window.open(this.href);return false; FROM http://www.winaltainc.com/sitemap/" onclick="window.open(this.href);return false;
FROM http://www.winaltainc.com" onclick="window.open(this.href);return false;" but I suspect that going deeper into it may not be economically feasible for me.

Microsoft has some interetsing snippets of code that may allow me to detect in more detail what is going on.

For now I can detect an "error" and can investigate it manually before emailing the client.
This is the first web site I've encountered in about 1,000 that exhibits this weird behavior.

I can examine the scripts in the parent web page (that points to sitemap). In the case of "http://www.winaltainc.com" Script Item(3) shows the details of the script for invoking the site map, but the names are specific to this site, so I don't see that as a general solution.

I think the layperson's answer is "When the user clicks on a link, the web page is smart enough to fire up some associated code (javascript) to bring the linked page into view.", and that a mere mortal in VBA does not have the ability to trigger that event on a link. That is, in VBA I am not able to, nor am I able to detect that I should, simulate a "click" on a link.

I'm going to make myself a cuppa and have a lie-down ... :nurse:
An expensive day out: Wallet and Grimace

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

StuartR wrote:NoScript is a Firefox add on, ...
Thanks Stuart.
An expensive day out: Wallet and Grimace

User avatar
mwolfman
The Man, The Myth, The Legend
Posts: 770
Joined: 16 Jan 2010, 00:14
Location: New Jersey

Re: VBA code fails to load a valid URL link, Why?

Post by mwolfman »

Chris - I use this thing called firebug for firefox. Lets me poke around all sorts of neat stuff on a site.

It looks like sitemap/ isn't an actual directory. If you try to go to a file that's not there, you get a normal 404 error.

http://www.winaltainc.com/sitemap/sitemap.xml" onclick="window.open(this.href);return false;

There's a bunch of code in the script that leads me to believe it's all in the code and you can't call it from a URL.

In the head:

Code: Select all

		<script type="text/javascript">
		$(document).ready(function() {
		 
		 // toggles the slickbox on clicking the noted link 
		  $('a#sm_toggle').click(function() {
		    $('#sm_outer').slideToggle(400);
		    return false;
		  });
		  
		  $('a#sm_toggle_close').click(function() {
		    $('#sm_outer').slideToggle(400);
		    return false;
		  });
		 
		});
		</script>
All the code of the sitemap is in the index page. (from what I can tell, php is tricky)

Summary - you can't call the sitemap from that link, BUT there may be a way to call it thru the index page. Did you create the site? So you have access to the php?
Mike Wolfman

--To err is human; to really screw up requires root

User avatar
mwolfman
The Man, The Myth, The Legend
Posts: 770
Joined: 16 Jan 2010, 00:14
Location: New Jersey

Re: VBA code fails to load a valid URL link, Why?

Post by mwolfman »

I can also see from the code, there is a CMS in the background. Prolly EE or Jomla and they both do exactly whats happening here. Just because the directory link is in the code, doesn't mean it actually exists. You're script will work or sites made WITHOUT these CMS's.
Mike Wolfman

--To err is human; to really screw up requires root

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA code fails to load a valid URL link, Why?

Post by ChrisGreaves »

mwolfman wrote:Summary - you can't call the sitemap from that link, BUT there may be a way to call it thru the index page. Did you create the site? So you have access to the php?
Mike, thanks again for your insight.
To answer your questions: I did not create this site. Right now I'm plucking sites from a "random" source, having first experimented on http://www.ChrisGreaves.com" onclick="window.open(this.href);return false; and uncovered more broken links than there are grains of sand in Australia, from what I remember.
I don't have access to the php, nor, I should think, to any aspect of the site that ought not be visible to a naive end-user.

Now (puts on parental hat) I thank you for your time, but really would rather you focused on maintaining and enhancing Eileen's Lounge.
I feel guilty about distracting you ....
An expensive day out: Wallet and Grimace

User avatar
mwolfman
The Man, The Myth, The Legend
Posts: 770
Joined: 16 Jan 2010, 00:14
Location: New Jersey

Re: VBA code fails to load a valid URL link, Why?

Post by mwolfman »

It's good, I need the distractions once in a while. I'm working on a bug that's driving me crazy right now and sometimes I need to step away and do something else.
Mike Wolfman

--To err is human; to really screw up requires root