Jump to content
UBot Underground

Having a bit of trouble with the $element child/offset code...


Recommended Posts

I don't think there is an easy way to get the result with combination that you mention above, you should use one or another, but I would advice you use another approach.

 

The easiest way would be to use "scrape table", but it has a down side which is that it can only be global.

scrape table(<id="query_list">, &TABLE)

You then have all your values in 1st column.

Link to post
Share on other sites

I agree with UBotDev with the ease of the "scrape table" node.  BUT since you made reference to the "$element child/offset" nodes I thought I would give you two examples.

 

First.  the "$element child" is not needed here for your table.  Typically, this node would be used to move between other objects containing other Children or even Parents.  However, the "$element offset" node is an interesting node and should be mastered by all botters at some point.

 

Example 1:

on load("Bot Loaded") {
    load html("<table width=\"100%\" id=\"query_list\" style=\"margin: 0px;\">
<tbody>
<tr style=\"text-decoration:underline; cursor:pointer;\">...</tr>
<tr>
<td>red robin</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr style=\"background-color:#f8f8f8;\">
<td>redbox</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr style=\"background-color:#f8f8f8;\">
<td>red robin menu</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>red hot chili peppers</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>")
}
set(#var1, $scrape attribute($element offset(<tagname="td">, #offset), "innertext"), "Global")
ui drop down("Offset", "0,4,8,12", #offset)
ui stat monitor("Cell value is ", #var1)

This example loads a version of the Table code that you provided.  I have it in an "on load" node so if you do not have that node in your version of UBot Studio then you will have to remove the code (on load("Bot Loaded") { and its matching "}".  You may need to add a wait (2) after the "load html" node.

 

The drop down is loaded with four values 0,4,8,12.  They represent the position of the text values that you have in the table cells.  Why do I use these numbers?  Because every cell in this case is identical in html structure.  There is a

and a .  That means you cannot tell them apart.  So there are 4 TDs to each row.  So the values 0,4,8,12 will allow us to move from row to row instead of cell to cell.

 

Now, the "$element offset" node gives us the ability to focus on one specific value to scrape.  The beauty is that we can now change the Offset value and more around in the same focussed manner.

 

Play with this code and you will be able to understand what's going on.

 

Now create another Tab and add the next code.

 

 

Example 2:

add list to list(%list1, $scrape attribute(<tagname="td">, "value"), "Don\'t Delete", "Global")
set(#loopcnt, $divide($list total(%list1), 4), "Global")
clear list(%list1)
clear list(%Results)
set(#index, "-4", "Global")
loop(#loopcnt) {
    set(#index, $add(#index, 4), "Global")
    add item to list(%Results, $scrape attribute($element offset(<tagname="td">, #index), "innertext"), "Delete", "Global")
}

This is a different variation of the first example.  Note how I figure out how many times I need to Loop through to scrape using my "$element child".  Remember, each row has 4 TDs so I build a temp list and I count the total number of TDs that I have and then I divide by 4 (four columns).

 

I then create my index (aka Offset for the $element offset).

 

Some may ask why I set my index to -4.  I am a programmer by training so I use structured programming practices...that's why.  lol.  But also note that when the bot is run, the final value of the index will be 12.  If you use zero then you will have to move the Set node to the bottom of the Loop or else you will miss the first value. 

 

Sorry this went a little long but I thought I would throw a lesson in here.

 

Good luck!

 

Buddy

  • Like 1
Link to post
Share on other sites

Hey thanks both for replying to me.

 

@Buddy, that was so epic, I am completely clueless of what you spoke ( don't worry, Im going to go over it word by word and understand this completely!) Glad that you mentioned structured programming practices :)

Link to post
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...