Jump to content
UBot Underground

Question about $replace


Recommended Posts

Little bit confused with its 3 fields

Original, Search, Replace

 

If I want all 1 to be replaced for 2 in scraped content

what should I put in each?

 

Replace is FUN. :rolleyes:

 

I nearly lost it on poor Alex a couple months back trying to figure it out but I eventually got it down and use it every day or more now.

 

You have to think of replace as having FOUR fields, not just the three you see when you open it. The fourth is found just before you open the replace pop-up, the thing you are replacing. Sometimes it is the same as the first setting (original) and sometimes it isn't... Depending on your needs at the time.

 

In your example above, it sounds like it would be.

 

If you're modifying your source information itself during the replacement, then it will be the exact same as your 'Original' value, in the first field. If you want to replace a source with something totally unrelated, say, the openeing words from the declaration of independence, then your source would be a totally different variable from your 'Original' variable.

 

The "search" and "replace" are just modifying the "original" value, not the source value. So to sum it up; the:

 

1. Source is usually a variable that exists where you want the new thing to be.

 

2. Original is either that same variable or another if you want to pull in some other content entirely,

 

3. Search is the specific text/code you're looking to replace inside 'original', and

 

4. Replace is just what you want to go there... Usually a variable or the $nothing function.

 

Hope that helps!

Luke

  • Like 1
Link to post
Share on other sites

GREAT post Luke! And you are forgiven if you post this super information in the tips and tricks sections :wub:

 

Since you used the "wub" smiley, how could I refuse? :rolleyes:

Link to post
Share on other sites

Since you used the "wub" smiley, how could I refuse? :rolleyes:

 

 

Yeah, this is dark stuff.

 

Generally with replace I tend to have the current item set to a variable and then remove that variable from a list and then save the list off. In that way I always have a list which is active and another which has the state of play.

Link to post
Share on other sites
Generally with replace I tend to have the current item set to a variable and then remove that variable from a list and then save the list off. In that way I always have a list which is active and another which has the state of play.

 

That's deep, dude.

 

Not to sound like a doubter, but what does this extra measure avoid, exactly?

 

BTW, the Laconibomb on your site sounds like an awesome idea... Was thinking about dabbling with laconia myself.

Link to post
Share on other sites

Replace is FUN. :rolleyes:

 

I nearly lost it on poor Alex a couple months back trying to figure it out but I eventually got it down and use it every day or more now.

 

You have to think of replace as having FOUR fields, not just the three you see when you open it. The fourth is found just before you open the replace pop-up, the thing you are replacing. Sometimes it is the same as the first setting (original) and sometimes it isn't... Depending on your needs at the time.

 

In your example above, it sounds like it would be.

 

If you're modifying your source information itself during the replacement, then it will be the exact same as your 'Original' value, in the first field. If you want to replace a source with something totally unrelated, say, the openeing words from the declaration of independence, then your source would be a totally different variable from your 'Original' variable.

 

The "search" and "replace" are just modifying the "original" value, not the source value. So to sum it up; the:

 

1. Source is usually a variable that exists where you want the new thing to be.

 

2. Original is either that same variable or another if you want to pull in some other content entirely,

 

3. Search is the specific text/code you're looking to replace inside 'original', and

 

4. Replace is just what you want to go there... Usually a variable or the $nothing function.

 

Hope that helps!

Luke

 

Hey Luke. I was wondering if you could help me apply this to:

 

http://ubotstudio.com/forum/index.php?/topic/4208-display-results-in-browser-window/

 

Thanks!

 

John

 

 

 

Link to post
Share on other sites

Hey Luke. I was wondering if you could help me apply this to:

 

http://ubotstudio.com/forum/index.php?/topic/4208-display-results-in-browser-window/

 

Hi John, I took a look and am trying to figure out what you'd want replaced with what over there... I can't tell what your original source is to build the list with, and why anything would need replacing since you seem to just be displaying everything on the list.

 

If all you want to do is replace one url with another then it's pretty straightforward... Of course how long you want the first one to display on your page before being replaced with a second becomes the new question.

Link to post
Share on other sites

Ok let me see if I can explain it better. here is the html code for an html file a created and placed in my documents folder:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TOP 30 CLICKBANK PRODUCTS BY GRA</title>
<style type="text/css">
.style1 {
text-align: center;
font-size: large;
}
.style2 {
text-align: center;
}
.style3 {
text-align: left;
}
</style>
</head>

<body>

<p class="style1"><strong>TOP 30 CLICKBANK PRODUCTS BY GRAVITY</strong></p>
<p class="style2"><script LANGUAGE="Javascript">
<!-- 

// Array of day names
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
			"Thursday","Friday","Saturday");

// Array of month Names
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");

var now = new Date();
document.write(dayNames[now.getDay()] + ", " + 
monthNames[now.getMonth()] + " " + 
now.getDate() + ", " + now.getFullYear());

// -->
</SCRIPT></p>
<p class="style2"> </p>
<ol>
	<li>
<p class="style3"><a href="Site1">Site1</a></p>
</li>
<li>
<p class="style3"><a href="Site2">Site2</a></p>
</li>
<li>
<p class="style3"><a href="Site3">Site3</a></p>
</li>
<li>
<p class="style3"><a href="Site4">Site4</a></p>
</li>
<li>
<p class="style3"><a href="Site5">Site5</a></p>
</li>
<li>
<p class="style3"><a href="Site6">Site6</a></p>
</li>
<li>
<p class="style3"><a href="Site7">Site7</a></p>
</li>
<li>
<p class="style3"><a href="Site8">Site8</a></p>
</li>
<li>
<p class="style3"><a href="Site9">Site9</a></p>
</li>
<li>
<p class="style3"><a href="Site10">Site10</a></p>
</li>
<li>
<p class="style3"><a href="Site11">Site11</a></p>
</li>
<li>
<p class="style3"><a href="Site12">Site12</a></p>
</li>
<li>
<p class="style3"><a href="Site13">Site13</a></p>
</li>
<li>
<p class="style3"><a href="Site14">Site14</a></p>
</li>
<li>
<p class="style3"><a href="Site15">Site15</a></p>
</li>
<li>
<p class="style3"><a href="Site16">Site16</a></p>
</li>
<li>
<p class="style3"><a href="Site17">Site17</a></p>
</li>
<li>
<p class="style3"><a href="Site18">Site18</a></p>
</li>
<li>
<p class="style3"><a href="Site19">Site19</a></p>
</li>
<li>
<p class="style3"><a href="Site20">Site20</a></p>
</li>
<li>
<p class="style3"><a href="Site21">Site21</a></p>
</li>
<li>
<p class="style3"><a href="Site22">Site22</a></p>
</li>
<li>
<p class="style3"><a href="Site23">Site23</a></p>
</li>
<li>
<p class="style3"><a href="Site24">Site24</a></p>
</li>
<li>
<p class="style3"><a href="Site25">Site25</a></p>
</li>
<li>
<p class="style3"><a href="Site26">Site26</a></p>
</li>
<li>
<p class="style3"><a href="Site27">Site27</a></p>
</li>
<li>
<p class="style3"><a href="Site28">Site28</a></p>
</li>
<li>
<p class="style3"><a href="Site29">Site29</a></p>
</li>
<li>
<p class="style3"><a href="Site30">Site30</a></p>
</li>
</ol>

</body>

</html>

 

 

Everywhere there is a "Site*" I want to replace "Site*" with the actual scraped urls from a previous function in the bot. At the end of the script run I will display the html file in the browser where the url's I added are now clickable links. So essentially I need to open the file and replace those "Site*" elements

 

Does that make more sense?

Link to post
Share on other sites

Ok let me see if I can explain it better. here is the html code for an html file a created and placed in my documents folder...

Everywhere there is a "Site*" I want to replace "Site*" with the actual scraped urls from a previous function in the bot. At the end of the script run I will display the html file in the browser where the url's I added are now clickable links. So essentially I need to open the file and replace those "Site*" elements

 

Does that make more sense?

 

I see... It will take a bit of work though. I'm thinking you'll need to run a loop for the number of items on your list... If it's always 30 just literally write in 30.

 

Inside the loop, you're going to start with 2 scrapes. Go to CB and scrape both the url (html link) and the target product name and save them as two variables, like #tempurl and #temproduct.

 

Next inside the loop you'll make 2 replacements, using #tempurl and #temproduct as your replace for each (third box).

 

The source file I believe will be the same as your Original, (1st box) and both would have in it the whole template inside a variable. (You should have that created now.)

 

The middle box, (search) the thing that gets replaced, is just the words "site1" or whatever you'll have placeholding the urls and the anchor text on those lines.

 

There is one problem though... I think. From the looks of your code above you've got the exact same word (Ex: site1) placeholding both the url and the product name... Can that be changed? Is this just a template? To make this work they should be different or the first replacement would replace both with the url and the name.

 

What you'd want instead is a line like this:

<li>        
<p class="style3"><a href="Site1url">Site1</a></p>        
</li>

 

..That way your Search boxes would be for Site1url and Site1.

 

Make sense?

-Luke

Link to post
Share on other sites

Thanks Luke...I half understand it. I had both variables the same because I was just going to show the link, but your way would be a lot cleaner.

 

I kind of get what I have to do, I just don't know how to get there! I have tried numerous things, but they either overwrite the html entirely or add nothing to it.

Link to post
Share on other sites

Thanks Luke...I half understand it. I had both variables the same because I was just going to show the link, but your way would be a lot cleaner.

 

I kind of get what I have to do, I just don't know how to get there! I have tried numerous things, but they either overwrite the html entirely or add nothing to it.

I'd do this, slightly different unless there is some requisite for uniqueness.

 

set a variable for the site number (like urlnumber)

Set the urlnumber variable to 1 outside the loop.

Go into the loop.

Max it to 30.

Search for <a href="Site[urlnumber]

Replace with URL, (these are in a list)

End of loop increment url number +1.

 

I think that's right. Hope you work it out.

 

;)

Link to post
Share on other sites

Thanks ninja! I am still muddling through it. I know it shouldn't be that difficult, but for some reason the more I think the harder it gets.

 

Should I be using a $read file prior to replacing anything?

 

Or is this a simple two part solution...

 

$replace (where the actual file is the original source)

 

and

 

save to file

 

There is no search text function and the text (html code) is not a list.

 

Where there is $list from text and $list from file, it would be nice to have $text from file (like adding it to to the clipboard for manipulation). I don't know. I will keep trying. Thanks again.

 

John

Link to post
Share on other sites

I'd do this, slightly different unless there is some requisite for uniqueness.

 

set a variable for the site number (like urlnumber)

Set the urlnumber variable to 1 outside the loop.

Go into the loop.

Max it to 30.

Search for <a href="Site[urlnumber]

Replace with URL, (these are in a list)

End of loop increment url number +1.

 

I think that's right. Hope you work it out.

 

;)

 

Ok, I read your post like 30 times and I think I totally understand what you are saying now. So given that structure, what would the input parameters for the replace function be?

 

source = #urlnumber

 

original = #urlnumber

 

search = <a href="Site[urlnumber]

 

replace = %next list item

 

And then do I have to save to file to keep the changes? Thanks again.

 

John

 

 

 

Link to post
Share on other sites

I can't get it. I tried and tried and tried again. I am posting the bot here in the event someone is willing to show me it's done. If you run the bot it will end up posting the urls at the end. They are in text format, but I want to place them within the html code above so it displays as a webpage instead of a text file.

 

Also, if you navigate to any one of those final url's you will see a gray table full of the information I would love to be able to scrape. Could that be done using the new tables feature? I truly have no clue what to do with the new feature, but it looks useful! lol Thank you.

 

John

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