Jump to content
Macro Express Forums

Erratic Copy Command


Recommended Posts

Please see If it was ease we would not need Macro Exoress

 

I am using 2 Internet Explorer Windows within my Macro. The first one contains different headings (which I need to select the one I want), once I click on a heading it loads a 2nd Internet Explorer window which contains the data I need to copy. When I copy the data, I am pasting it into Ultra Edit. Below is the Macro I put together.

Window Activate: Construction Services
Wait for Window Title: Construction Services
Mouse Left Click
Mouse Left Click
Mouse Move: 2257, 677 Relative to Screen
Mouse Left Button Down
 Mouse Move: 2750, 850 Relative to Screen
Mouse Left Button Up
Clipboard Empty
Clipboard Copy
Window Activate: UltraEdit
Wait for Window Title: UltraEdit
Text Type (Simulate Keystrokes): <CONTROL><END>
Text Type (Simulate Keystrokes): <ENTER>
Clipboard Paste

Nothing seems to work consistent. I have tried adding time delays. The macro will run through a few times with no problems, then it misses the copy command. Can anyone suggest a better way to do this. If you want to see for yourself what I am doing, the first IE window is at www.mbaonline.org, click "Find a Member" in the upper right corner, click on I accept. Then click the Construction Services Tab and select a heading. At the bottom, different companies appear. If you click on "More Detail," the 2nd IE Window will open with the Text we are trying to copy.

 

Thanks for any help or suggestions.

 

Bob

Link to comment
Share on other sites

Some ideas.

.........................................................................

FYI I am now using a VBScript to download the HTML text without the browser. Works 100% consistently and lighting fast. If you want to learn how let me know.

 

It appears you are using the mouse to highlight everything in Internet Explorer. I suggest you try CTRL+A instead. That will select everything in the web browser.

 

As for the clipboard performance I suggest two things. First try both the CTRL+C combo and the Clipboard commands in MEP. Next, and I keep telling you this, you need to put a delay after your clipboard copy. I recommend at least 250mS but if that doesn’t work make it something gross like 1 second then reduce the time until it becomes inconsistent. Clipboard events take time and you’re jamming ahead to the UltraEdit instantly and pasting. Most likely the clipboard is not ready yet when it fails.

Link to comment
Share on other sites

Cory,

 

To answer your first question, we can't use a CTRL+A because we only want the text that is within the box on the page.

 

I also added the second manual copy command like you suggested as well as some delays in a few spots. The time delays never really seem to be consistent though. I went through and added them and then took each one down until I had problems running the macro through. But it still is not consistent. It might run through 3 times and then start missing one or two. I also added a Repeat Prompt because there are always a different number of contacts or companies.

 

This is the new code:

Repeat Prompt Start
 Window Activate: Metropolitan Builders Association
 Wait for Window Title: Metropolitan Builders Association
 Wait for Left Mouse Click
 Delay: 1.5 seconds
 Window Activate: Construction Services
 Wait for Window Title: Construction Services
 Mouse Left Click
 Mouse Left Click
 Mouse Move: 2272, 660 Relative to Screen
 Delay: 300 milliseconds
 Mouse Left Button Down
Mouse Move: 2758, 830 Relative to Screen
Delay: 300 milliseconds
 Mouse Left Button Up
 Clipboard Empty
 Clipboard Copy
 Delay: 200 milliseconds
 Text Type (Simulate Keystrokes): <CONTROL>C
 Delay: 1 seconds
 Window Activate: UltraEdit
 Wait for Window Title: UltraEdit
 Text Type (Simulate Keystrokes): <CONTROL><END>
 Text Type (Simulate Keystrokes): <ENTER>
 Clipboard Paste
End Repeat

 

One other thing I did notice is that after the Macro is done running the "little man" is still in the Taskbar...am I missing something in the code? I tried with and without the repeat and either way he is still there.

 

Thanks once again for all your help Cory.

 

Heather (for Bob)

 

PS We would really be interested is learning about the VBScript. We have dabbled in it a very little bit through other programs. Let me know how you want to do it...

Link to comment
Share on other sites

VBScript.

.....................................................................

We would really be interested is learning about the VBScript. We have dabbled in it a very little bit through other programs. Let me know how you want to do it...
In the future you might take a little time to read other posts besides follow ups to your own as we often post little nuggets like this one I wrote on that VBScript for downloading a web page. To do what you want you will need to read the resulting HTML file into a variable and parse out the data you need. It's not too difficult. Open it in Notepad and find a unique marker just before the text you want. In the macro use the Set Integer to Position of Text in a Variable. Then see what the offset is to the beginning of the text you want and add that to that variable. Now just delete everything from the beginning to that position. Now do the same for the end of the text you want. It sounds like more work but it is the best way to do it. No timing, no dependence on other applications, and it happens nearly instantly.

 

Example: In my other post I download an XML file which is really just a structured HTML file. Let’s say I want to get the titles. In the text my titles have tags in front and behind it like “<title>The Title of something</title>” So if I wanted to grab 10 titles it might look like this:

  1. Set %Downloaded File% to the contents of the downloaded file.
  2. Repeat 10 times storing the counter in %Counter%
  3. Set the variable %Position% to the position of <title>
  4. Add 6 to %Position%
  5. Delete part of %Downloaded File% from 1 to %Position%
  6. Set the variable %Position% to the position of </title>
  7. Decrement %Position%
  8. Copy part of %Downloaded File% from 1 to %Position% to %Title[%Counter%]%
  9. Add 8 to %Position%
  10. Delete part of %Downloaded File% from 1 to %Position%
  11. Repeat End

When I’m done my Titles array from 1 to 10 would have the first 10 titles.

 

I think if you take some time to learn it you will be happy. With the exception of the download time, which is usually a second or two, you can have thousands of lines like this and it will work every time perfectly, be invisible and happen instantly. IMHO it’s better to spend the time this way than banging your head against the wall with clipboard and application timing issues! :)

Link to comment
Share on other sites

Cory,

 

Bob and I discussed that very thing. Not only searching a little more through the forum, but actually searching through our own messages we have posted. When we get through a problem we usually archive the message in our own "Help System" so to speak. We will check out that post and like always, thank you so much for your help and patience!

 

I do however, have one more question. In the code I did do, can you see why I am ending with the "little guy" in the taskbar still? When I put in the number of times I want to repeat, I would think it would end after that, but the little guy remains. Maybe I am still missing something or not ending the Macro the proper way. It seems that I am getting a time error on Line 2. It pops up well after I am done running the Macro.

 

Thanks,

 

Heather

Link to comment
Share on other sites

Is it possible the COPY TO CLIPBOARD command is running before the web page has finished loading? Try throwing in three or four WAIT FOR WEB PAGE TO LOAD commands (wait indefinitely) after (or in place of) each of the WAIT FOR WINDOW TITLE commands. Each web page wait takes a minimum of about a second, but if IE goes to "not busy" several times in the course of completing the page load, you may need more than one wait.

 

Don't use both a CLIPBOARD COPY and TEXT TYPE <CONTROL>c -- they both do the same thing. Try one or the other, but not both.

Link to comment
Share on other sites

I don't see anything wrong with it.

.................................................

Unless the last Wait For is still waiting.

 

Do yourself a favor and put a “Beep” as the last command. That can act as an audible annunciator for when it’s complete. That command can be found in the Multimedia section.

 

But it has been discussed here that Forrest (my nickname for the running man) often gets stuck and doesn’t appear responsive. If you hover him and he doesn’t report that he is running a macro in a balloon then I think you’re just seeing the stuck Forrest bug. Have you upgraded to 4.1.1.1?

Link to comment
Share on other sites

I'm not sure what the 2 Mouse Left clicks are! If you don't use Mouse Move first, the mouse can be anywhere.

 

I can see that you cannot directly access the page due to the scripting. The URLs do not change very much. If page design is consistent over time you can use a mouse. Keystrokes like Tab, Shift+Tab, arrows, Enter cope better with minor changes in page layout.

 

If results are inconsistent, do not underestimate times for selecting, copying, pasting large amounts of data. If problems, make 2-3 secs and work down.

 

Sometimes you can save a lot of work by running through the process manually and observing URLs in the location bar of the browser. You can fabricate the URL with MEP. For example, my TV listings are typically:

 

xxxx://affiliate.zap2it.com/tvlistings/ZCSGrid.do?stnNum=17609&channel=&fromTimeInMillis=0

Note that I have subbed xxxx for http so they don't appear as links in the forum!

 

I would construct for different stations.

variable xxxx://affiliate.zap2it.com/tvlistings/ZCSGrid.do?stnNum=

add station ID 17609

add variable &channel=&fromTimeInMillis=0

xxxx://affiliate.zap2it.com/tvlistings/ZCSGrid.do?stnNum=17609&channel=&fromTimeInMillis=0 is typed in the location bar

 

I have a list of all the station IDs in a text file and call them up one by one (Text File Process)

 

This is what I would do for your listings. I would make a set of macros, one for each frequently accessed item eg Accounts, Apartments. Same macro, different URLs and arrow navigation. No timings included but illustrates many techniques

 

MBA Home Page loads

Type 4 Tabs + Enter loads disclaimer

Page Down (once or twice, too many better than too few times)

Mouse move over I agree button, mouse left click

Type Alt+D IE location bar

TypeURL xxxx://www.mbaonline.org/MBAGeoLocator/ConstructionServicesMaterials.aspx (will be in location bar)

Edit: I found that if you load this link (with the http of course) you can omit all the previous steps, disclaimer etc. It may be that cookies have been set in my browser from previous accesses but if it works it saves a few steps.

Page loads

Move mouse near centre of listbox, mouse left click

Type 4 arrows up (too many better than too few) to get to top of list

Type Down arrows as required (eg 7 down arrows will give you Apartment Management)

Type 2 Tabs + Enter to hit Search

Page loads

Type one or two Page Downs (depends how big the list is, one probably will do)

Sound a Ding (to get your attention cos you've been twiddling your thumbs up to now)

Wait for mouse left click

 

(You manually click More Details of desired entry)

Page loads

Copy data similar to what you were doing etc etc

End with more emphatic sound file

 

It all sounds complicated but once you have done it you will find others easier. My TV listings were very complex because I do Stations and Actor/Show Searches and pages can take 5-90 secs to load. It took 8 hours to get the macro working consistently but since it runs 2 hours every night, the savings have been astronomical.

Edited by JohnS
Link to comment
Share on other sites

For example, my TV listings are typically:

 

xxxx://affiliate.zap2it.com/tvlistings/ZCSGrid.do?stnNum=17609&channel=&fromTimeInMillis=0

Note that I have subbed xxxx for http so they don't appear as links in the forum!

[etc]

 

John,

 

Could you summarise briefly what your purpose is with this/these macros please? IOW, what is the end result?

 

So far I've not found my 'ideal' TV listings/search/reminder program or online service, which is why I'm curious.

 

P.S. By PM or a new thread, as I've accidentally taken this OT. ;)

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

If you followed the steps that I showed for automating and have not had enough fun yet, you can complete the exercise! I don't suppose you want to bother but I include for info.

 

If you wanted to input the data directly into a particular format or variables (and also avoid using the mouse) you could extract the data. It helps in these situations to have a basic knowledge of HTML but not essential. I only show the principles, not every step:

 

Company details page loads

Type Alt+V (IE only)

Type C opens page source (IE only)

Edit:

Note: If you find the details page has no menu bar, you will have to use mouse right click, type "v" to show source

Type Ctrl+A

Type Ctrl+C copy page source

Set text variable, say T50, to clipboard content

Close page source window

 

Extract data:

To extract company name:

Copy T50 to T51 so you can re-use T50

Find position of <td id="val_CompanyName" align="center" valign="middle"> in T51

Delete T51 up to and including <td id="val_CompanyName" align="center" valign="middle">

Find position of next < in T51

Delete all of T51, past, and including the <

Copy T51 to T60, this is the company name

 

To extract street address

Copy T50 to T51 so you can re-use T50

Find position of <td id="val_Address" align="center" valign="middle">

etc etc

Copy T51 to T61, the street address

 

etc

 

Use the extracted variables however you want.

Depending on how the HTML was written it may be an idea to Trim the final strings to remove any unwanted spaces

 

Using all the steps I've detailed, the only manual action would be to start the macro and to select the company you want details of.

Edited by JohnS
Link to comment
Share on other sites

You might use EZTV.it

...........................................

I download all my TV (No cable or satellite) and there are places like EZTV where people post torrents of the shows and usually it’s right after they show. I use their RSS feed with my torrent app µTorrent and the RSS Downloader downloads my shows automatically. I don’t know what you want to do but you might be able to use this. Also one can use the RSS feed with the script I provided and make ones own RSS downloader and processor. I do that for my games but it could be used for anything.

Link to comment
Share on other sites

  • 3 months later...

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...