TAG and SEARCH parameters

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

TAG and SEARCH parameters

by rdone on Wed Apr 12, 2017 10:16 am

And now for Part II of viewtopic.php?f=7&t=27429
One possible outcome of a friend search on FriendlyFriends.com is that a friend was not found. In that case, the resulting web page contains the following:
<div id="FriendListing" class="NoFriend">
<p class="NoFriendSummaryText">I'm sorry, but your friend was not found.
</p>
</div>
If I get this result then I want to append the csv record with some relevant notation but I first have to detect this result instead of other possible results. I tried the following but neither work:
SEARCH SOURCE=TXT:"'NoFriendSummaryText'" IGNORE_CASE=YES
TAG POS=1 TYPE=A ATTR=TXT:*sorry*
Both the macro fails at both cases at the above line.
I think either command will work and I think I just need help with the parameters. I found the above by searching the demo macros and command reference and forum but didn't find an exact solution. Thanks in advance for any help fixing the parameters (ideally for both options).
iMacros for FF v9.0.3, FF52-x32, Win7-x64
rdone
 
Posts: 7
Joined: Wed May 26, 2010 2:09 pm

Re: TAG and SEARCH parameters

by chivracq on Wed Apr 12, 2017 11:10 am

rdone wrote:
Code: Select all
iMacros for FF v9.0.3, FF52-x32, Win7-x64[

And now for Part II of viewtopic.php?f=7&t=27429

One possible outcome of a friend search on FriendlyFriends.com is that a friend was not found. In that case, the resulting web page contains the following:
Code: Select all
<div id="FriendListing" class="NoFriend">
   <p class="NoFriendSummaryText">I'm sorry, but your friend was not found.
        </p>
</div>

If I get this result then I want to append the csv record with some relevant notation but I first have to detect this result instead of other possible results. I tried the following but neither work:
Code: Select all
SEARCH SOURCE=TXT:"'NoFriendSummaryText'" IGNORE_CASE=YES
TAG POS=1 TYPE=A ATTR=TXT:*sorry*

Both the macro fails at both cases at the above line.

I think either command will work and I think I just need help with the parameters. I found the above by searching the demo macros and command reference and forum but didn't find an exact solution. Thanks in advance for any help fixing the parameters (ideally for both options).

iMacros for FF v9.0.3, FF52-x32, Win7-x64

OK, good for FCI mentioned, even if you could mention it at the complete top of your OP, that's the first bit of Info I look for when checking a new Thread to decide if I will read or not...

Good that you mention the direct Link to your previous Thread as this current one is indeed a bit following up on the previous one, BUT...!, every Thread should be a completely Standalone Thread, with all relevant Info... You had mentioned some URL to the Site in the previous Thread, it would be needed as well in this current Thread with some concrete Script to reach a relevant Page as a "real" Example, I don't play "little Detective" to go and fetch some Data from this previous Thread... and to try to reach some Page that will display what you mean...

I don't exactly/completely understand what you want to do, and to be honest, even if I can consider myself an Advanced User I think, I don't like this 'SEARCH' Command that I consider very difficult to use (I tried it once, 1 or 2 years ago for some older Thread, and I didn't get it to work properly then, maybe because using as well the 'REGEXP' Parameter which I don't like and find very difficult to master and to use, but your Case might be "easier" as you use the 'TXT' Parameter instead which is probably more "straightforward")...

'SEARCH' will search the Source of the complete HTML Page, but I see some "<div id="FriendListing" class="NoFriend">" in your Source Excerpt, meaning you already have the ID and the Class of some 'DIV' containing the Data you are looking for, => then I would think it's probably easier and more reliable to use those 2 Attributes to identify/locate more reliably the Field/Data you want to locate/extract and to use the 'EXTRACT' Mechanism on that 'DIV'.

If I get this result then I want to append the csv record with some relevant notation...

=> Okay..., but hum, what do you mean exactly...? What do you want to do concretely...?

Code: Select all
SEARCH SOURCE=TXT:"'NoFriendSummaryText'" IGNORE_CASE=YES
TAG POS=1 TYPE=A ATTR=TXT:*sorry*

Both the macro fails at both cases at the above line.

=> This is a vague Statement and I don't understand what you mean exactly..., maybe because the Sentence is grammatically not correct and for me completely confusing, with a complete mix-up of Singular + Plural:
"both" is plural (=2), "the macro" is singular, "both cases" I don't understand which "both cases" => 'IGNORE_CASE' =YES/NO...?, or the 'SEARCH' + 'TAG' Statements...?, or Friends found/not found...?, "at the above line" (= Singular) but there are 2 Lines.
And "fail(s)" (or "doesn't work", ah-ah...!) is always vague...! Do you get any RuntimeError...?, what do you expect and what do you get...?

Your 'TAG' Statement is clicking on some Link containing the Word "sorry" but you don't say anything about that and it doesn't fit with the rest of your Description in your Post...

:idea: => I would say, post your complete Script and try to explain exactly/concretely what you want to do and what exact Result you expect... :idea:

You can use the following Statement as well to debut your Script a bit:
Code: Select all
PROMPT _{{!EXTRACT}}_

The 'PROMPT' Command is always your "best Friend" to follow your Vars and debug your Script... 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5962
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: TAG and SEARCH parameters

by rdone on Wed Apr 12, 2017 1:29 pm

In an unexpected but positive turn of events, I figured out not only parts of not only the TAG command but also the SAVEAS command. This part runs without error:

TAG POS=1 TYPE=* ATTR=CLASS:NoFriendSummaryText&&TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Projects\ScrapeScript FILE=Friend.csv

The above appends the text contained in the NoFriendSummaryText class to the Friend.csv file. However, the NoFriendSummaryText class only appears if the search produces no results (other classes appear when one or more results are produced) so what I need to do is determine IF this class appears and THEN append the current record in the csv file containing the search values with the phrase "No Friend" rather than appending a different file with the contents of the class. If I can get past this then I should be able to adapt that solution to deal with results when one or more friends are found by the search. Once this works then I will start with a csv file containing friend names and end up with the same file but with an additional column containing the search results (e.g., No Friend) for each of the friend names.

I see two tasks:
1. The IF/THEN part to determine if a particular class is contained in the page; and if so then
2. Appending the record with text other than the contents of the class.

I think the !EXTRACT variable could be part of the solution but I'm more than a little lost and any help is appreciated :(
rdone
 
Posts: 7
Joined: Wed May 26, 2010 2:09 pm

Re: TAG and SEARCH parameters

by chivracq on Thu Apr 13, 2017 12:09 am

rdone wrote:In an unexpected but positive turn of events, I figured out not only parts of not only the TAG command but also the SAVEAS command. This part runs without error:

Code: Select all
TAG POS=1 TYPE=* ATTR=CLASS:NoFriendSummaryText&&TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Projects\ScrapeScript FILE=Friend.csv


The above appends the text contained in the NoFriendSummaryText class to the Friend.csv file. However, the NoFriendSummaryText class only appears if the search produces no results (other classes appear when one or more results are produced) so what I need to do is determine IF this class appears and THEN append the current record in the csv file containing the search values with the phrase "No Friend" rather than appending a different file with the contents of the class. If I can get past this then I should be able to adapt that solution to deal with results when one or more friends are found by the search. Once this works then I will start with a csv file containing friend names and end up with the same file but with an additional column containing the search results (e.g., No Friend) for each of the friend names.

I see two tasks:
1. The IF/THEN part to determine if a particular class is contained in the page; and if so then
2. Appending the record with text other than the contents of the class.

I think the !EXTRACT variable could be part of the solution but I'm more than a little lost and any help is appreciated :(

Hum, OK, but you don't react on one single of my Remarks/Suggestions, so I'm not digging into your last Content, URL is still missing anyway...
Good luck with other (Advanced) Users, I'm out of this Thead... 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5962
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: TAG and SEARCH parameters

by rdone on Fri Apr 14, 2017 3:43 pm

OK, I appreciate the help you were able to give and I will try to do better in the future.
rdone
 
Posts: 7
Joined: Wed May 26, 2010 2:09 pm

Re: TAG and SEARCH parameters

by chivracq on Fri Apr 14, 2017 7:05 pm

rdone wrote:OK, I appreciate the help you were able to give and I will try to do better in the future.

Hum, I read your 2nd Post again, and I would say, try to extract both the Field(s) when Friends are found + not found, even if the Result can only be one or the other, but you will get 2 Extracts and therefore 2 Columns in your 'SAVEAS' File, when a Field is not found, 'EXTRACT' returns "#EANF#".
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5962
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 2 guests

-->