Jump to content
UBot Underground

I think I need string for this


Recommended Posts

OK, after going through the sticky string thread above, I only have a vague idea on how they should be used, and no idea on how to create them. I'm learning Javascript through osmosis at this point. Here's what I want to do:

 

I want to scrape an authors name from a webpage and use that as a variable. With certain sites the scraped author id/tag ends up looking like this: Posted by Squiggy.

 

I want to get rid of "posted by" each time I scrape for the authors name. I just want to end up with "Squiggy" as my variable. This sounds like something I would need to use a string for. (I'm guessing) How would I do this?

 

Here's another one:

 

I know how to scrape the URL of the page your on. I want to use a simplified shortened version of the URL as a variable. Example:

 

I want to take this: http://ubotstudio.com/forum/index.php?/forum/21-scripting/

 

And end up with this: ubotstudio.com

 

I'm guessing I would do this also with a string. How would I do this? (Somebody should do a video tutorial on this.) ;-)

Link to post
Share on other sites

OK, after going through the sticky string thread above, I only have a vague idea on how they should be used, and no idea on how to create them. I'm learning Javascript through osmosis at this point. Here's what I want to do:

 

I want to scrape an authors name from a webpage and use that as a variable. With certain sites the scraped author id/tag ends up looking like this: Posted by Squiggy.

 

I want to get rid of "posted by" each time I scrape for the authors name. I just want to end up with "Squiggy" as my variable. This sounds like something I would need to use a string for. (I'm guessing) How would I do this?

 

Here's another one:

 

I know how to scrape the URL of the page your on. I want to use a simplified shortened version of the URL as a variable. Example:

 

I want to take this: http://ubotstudio.com/forum/index.php?/forum/21-scripting/

 

And end up with this: ubotstudio.com

 

I'm guessing I would do this also with a string. How would I do this? (Somebody should do a video tutorial on this.) ;-)

 

The first one is easy. Just use the $replace command to replace "Posted by " with $nothing

 

The second needs either javascript or regex but is most easily done with the functions in the strings lib which you will find on this forum. Using that you could use $replace to get rid of http:// as the example I gave above for the posted by thing. Then do a $replace on the new string to replace "www." with $nothing just incase the url has that in front of it. Then use the string position function in the library to get the position of the first / (after stripping the http:// the first one will be the one after the domain name) store that in a variable and decrease by one. Use the substring to get everything from the start up to that position.

 

Write the whole thing into a sub of your own and you can reuse the code whenever you need to achieve that :)

 

Andy

Link to post
Share on other sites
The first one is easy. Just use the $replace command to replace "Posted by " with $nothing

 

Ah ha! OK thanks Net66. I've got that working. Next question is, am I doing it right? I'm basically resetting the variable and applying the replace command like this:

 

http://img375.imageshack.us/img375/249/setrepace.png

 

I'm basically removing some bold tags from my scraped authors name. Am I doing it right? Is there a better way to change/replace variables?

 

=== The second part - working with strings ====

 

Lemme as this: Can javascript use GREP searches?

 

In my fancy schmancy text editor (BBEdit), I can use GREP to replace long strings of text. As an example:

 

stupidwebsite.com/88383f9d9dg949ds4278

 

FIND: com.*.

REPLACE: com

 

Gets me this: stupidwebsite.com

 

Is there some way of doing that with Javascript and using it within a string? If not, how would I trim off that stuff at the end? God damn it, THIS is what I want Seth!! :-)

 

http://img294.imageshack.us/img294/6609/usegrepexample.png

Link to post
Share on other sites
  • 5 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...