Indrid Posted July 12, 2012 Report Share Posted July 12, 2012 Good Afternoon Macro Gods, I appeal to you for help in resolving an issue I've been having for quite some time. In my macros I often have to scrape data from a webpage that isn't formatted for easy macro searching, as such I usually have a macro search through the source code for the webpage I'm trying to scrape data from for what I need. The webpage is written with tags that always surround the data I need, the tags are specific to each value that needs to be parsed. Currently I use notepad and the find function to select the text I need, then set it to variables for later use from there. Is there a better way to do this that can scrape this data out in the background without using Notepad? I'd imagine there is, however I can't find any macro commands that let me set text between two expected text strings. Here's a sample of the source code I'm trying to scrape data from so you can get an idea: InitData("MV_MOVEMODEM", "False", "L"); dataarrayOld["MV_MOVEMODEM"]=dataarray["MV_MOVEMODEM"]["val"]; InitData("MV_EMAIL", "", "C"); dataarrayOld["MV_EMAIL"]=dataarray["MV_EMAIL"]["val"]; InitData("MV_MOVEFAX", "False", "L"); dataarrayOld["MV_MOVEFAX"]=dataarray["MV_MOVEFAX"]["val"]; InitData("MV_MOVEREASON", "NH", "C"); dataarrayOld["MV_MOVEREASON"]=dataarray["MV_MOVEREASON"]["val"]; I need to capture the data between InitData("MV_MOVEREASON", " and ", "C"); for example. Quote Link to comment Share on other sites More sharing options...
dcman98 Posted July 13, 2012 Report Share Posted July 13, 2012 This may all be common knowledge to you, but if so perhaps it will help someone else. There is an ability to reduce a text variable by text strings, as a combination of several steps. 1) Put this text into a text variable 2) Set an integer variable (N1) based on the text string length. 3) Set another integer variable (N2) based on "Get position of text in a text variable", and set the text to find to be "MOVEREASON" 4) Select a third integer variable (N3) using Variable Modify Integer to be N1-N2 (the length of everything after your starting point) 5) Use Variable Modify String and select "Copy part of text" to modify the string. Use N2 as the starting position and N3 as the length. Then modify these steps so that it also removes everything after the piece you want. You will be left with just a text string that contains your data. Please note that these steps are the general steps to get your result, but not necessarily exactly what you need. For example, I believe that the result for N2 will actually give the character number for the M in MOVEREASON, so you may have to add a step to add a 13 to get to the actual starting character you want. Quote Link to comment Share on other sites More sharing options...
Indrid Posted July 31, 2012 Author Report Share Posted July 31, 2012 My god that worked! You sir, are a gentleman and a scholar. Quote Link to comment Share on other sites More sharing options...
garlicnonions Posted April 10, 2014 Report Share Posted April 10, 2014 This example helped me out a lot! I wonder if there is a way to get the text to find "movereason" to be a variable so the command could loop through the text file to extract other portions of text? Quote Link to comment Share on other sites More sharing options...
dcman98 Posted April 23, 2014 Report Share Posted April 23, 2014 I'd think that if you defined the text variable, then for the search text put in that variable with the required % signs around it, it would work. Test it out and let us know. Quote Link to comment Share on other sites More sharing options...
garlicnonions Posted April 25, 2014 Report Share Posted April 25, 2014 Thanks dcman98! That does indeed work ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.