Jump to content
Macro Express Forums

Find And Click Link On Web Page


jokeeffe

Recommended Posts

Hello -

 

I am trying to automate downloading files from a frequently updated web page. This involves finding links on the web page and clicking on them. I can do this relatively easily in IE, using IE's Edit -> Find command:

 

Edit -> Find

Enter link text

Cancel Find dialog

<TAB> to select link

<ENTER> to goto link

 

However, my problem is that there are many links on the page with the same name, and I want to only activate the ones that I have not previously visited.

 

What I would really like to do is to highlight a link using the technique shown above, then move the mouse to that link so that I can examine the pixel color, and then decide whether or not to follow the link based on the pixel color. But I haven't been able to find any way to move my mouse to the currently highlighted text in a web page, or to the link which currently has focus.

 

Any ideas on how to accomplish this, or alternate techniques that might be helpful?

 

Thank you.

Link to comment
Share on other sites

Welcome to the forum!

 

It would be nice if the Move Mouse to Text command worked on Internet Explorer links, but it doesn't. My guess is that IE, like Word, uses its own text cursor.

 

So, one alternative is to take a snapshot of the screen, saving pixel pairs to a text file. Then use your sequence:

 

Edit -> Find

Enter link text

Cancel Find dialog

<TAB> to select link

 

Now the link is highlighted, therefore the colors have changed. Now rescan the screen comparing the pixel pairs until a difference is found, then move your mouse to that point.

 

I have not tried this yet, but I am about to because it sounds fun. My only concern is the speed, but this can be cut down by scanning every 10th pixel or so, by only concentrating on part of the screen, and so forth.

Link to comment
Share on other sites

Hi Joe,

 

Any reason why the web page cannot be directly scanned looking for the colour of a highlight/unvisited link? I have not scanned the screen myself but there are plenty of posts on the subject.

 

Do the find link logic as far as the Tab. Then scan for the screen highlight colour (typically blue) and find the first point where the next pixel is an unvisited link colour (assumed scanning left to right). You have the location of an unvisited link and can then do the Enter etc.

 

Logic needed to find successive links.

Link to comment
Share on other sites

Sure Noggin ... your idea would work, too.

 

There are some bad things involved in scanning for pixel colors. Speed, knowing which color, and so forth. My idea has some big flaws. The good thing about it is that there is no need to worry about which color to look for, only that a color has changed. The bad thing for this approach is a web site may have animated gifs or flash boxes so colors change constantly. Another bad thing is that searching for the next link could scroll the screen if the next link is not in the window.

 

It used to be that a count of links could be made by parsing the source code for any web site. But with today's web sites that is next to impossible to do.

 

Something that I've been trying lately is to turn off cache and loop (tab by tab) through a page keeping a count as I go.

Link to comment
Share on other sites

Hi Joe,

 

You're right about alternative methods no longer being practical due to web design. My first reaction to jokeefe's problem was to use a leeching program like LeechGet (one of the better non-spyware downloaders). Unfortunately it will not work if the link pointed to is a web page or one protected against leeching.

 

I would not choose to scan for colours. However the method I outlined requires two successive pixels of specific and different colour. The chances of that happening randomly are about nil (10**16?).

 

I'm not sure that the screen scrolling is a problem. If the logic used to go to the next link is ok (open link in new page/close page/find next occurrence of search string on first page?), it should not matter where it is. The highlighted link will be on the screen and be found by the colour search. Haven't tried it so can't be sure.

 

If looking for link colours, it would also be better to set IE to use the user's colours rather than the page's colours. My method of two colours should not make that necessary.

 

later edit

I wrote a macro to scan for a unique pair of pixels. Works great. Problem - when you find the link text in IE using jokeeffe's little routine, the area highlighted goes (typically) to blue background/white text which are very common Windows colours. The link colours disappear. Not good because blue/white will be elsewhere. Back to the drawing board for me.

 

even later edit

It's impossible to tell if any link has been visited if it is highlighted. The link colours disappear into highlight colours. You could tell with some very complex logic.

 

A totally different route to take is to compare the filename to be downloaded with a list of previously downloaded files.

 

Use the Find to get to the first link. The page needs to be preserved so that the link remains highlighted and the page is not reset. After the first link has been processed, use Find Next to get to the next link. Process all links in this fashion.

 

The method to check for previously downloaded files depends on your surfing/file moving habits.

 

At each link, do the necessaries to save the file to disk such as right-click/Save Target As or whatever. If the file has been previously downloaded and is still on disk in the download folder, you will get an error message about replacing file (window Save Web Page). Get the macro to respond No (type N, Esc after all saves).

 

If you frequently move files out of the download folder the procedure is a bit more complicated. Each time a file is saved, append the filename to a text file. When doing the file save operation, copy the filename to the clipboard, save as a variable and compare with the list of downloaded files in the text file. If already downloaded, cancel the save. If the file is not previously saved, save and append the filename to the text file list. The text file list can be partly cleared manually or by macro when it gets too big.

 

Not knowing the nature of the link makes it difficult to be precise. Eg is the link to a web page with a file link, or direct to a file? What type of file?

 

This is the method I would use because I have a number of macros that could be adapted to each phase.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...