Bot-Factory 602 Posted December 24, 2013 Report Share Posted December 24, 2013 Hello. I have the html code of a website in a variable.Now I want to extract a specific information out of this variable. The easiest would be, if I could use something similar to $Page scrape.Where I just enter:text on left sidetext on right side. But instead of doing that from tha actual page I'm on, I need to do that from the text within a variable. Within the html code ther is:<meta name="csrf-token" content="22546d0ed677b61e4073515e847773b52a363f1a882e45afa75eb87ad29c375cb9eab5024cafbc6ae1783d7d42fc73a54174ecb7bf4b82edadc8fe358a71f6ee"> And I need to extract only the token from the html text in the variable. What is the easiest way to extract parts of a text from another text? I looked at the text and search functions within ubot, but wasn't able to find anything that is similar to the $Page scrape command. Thanks in advance for your helpDan Quote Link to post Share on other sites
UBotDev 276 Posted December 24, 2013 Report Share Posted December 24, 2013 You should use regular expression, here is an example: (?<=content=").*?(?=") Quote Link to post Share on other sites
Anonym 53 Posted December 24, 2013 Report Share Posted December 24, 2013 set(#sourceString, "<meta name=\"csrf-token\" content=\"22546d0ed677b61e4073515e847773b52a363f1a882e45afa75eb87ad29c375cb9eab5024cafbc6ae1783d7d42fc73a54174ecb7bf4b82edadc8fe358a71f6ee\">", "Global")set(#extractedStr, $list item($find regular expression(#sourceString, "(?<=<meta name=\"csrf-token\" content=\")[a-zA-Z0-9]*(?=\">)"), 0), "Global") The extracted string is in the variable #extractedStr . If #sourceString is a web page you could extract the extracted string from "$document text" instead. Quote Link to post Share on other sites
mk21 1 Posted December 25, 2013 Report Share Posted December 25, 2013 Hello. I have the html code of a website in a variable.Now I want to extract a specific information out of this variable. The easiest would be, if I could use something similar to $Page scrape.Where I just enter:text on left sidetext on right side. But instead of doing that from tha actual page I'm on, I need to do that from the text within a variable. Within the html code ther is:<meta name="csrf-token" content="22546d0ed677b61e4073515e847773b52a363f1a882e45afa75eb87ad29c375cb9eab5024cafbc6ae1783d7d42fc73a54174ecb7bf4b82edadc8fe358a71f6ee"> And I need to extract only the token from the html text in the variable. What is the easiest way to extract parts of a text from another text? I looked at the text and search functions within ubot, but wasn't able to find anything that is similar to the $Page scrape command. Thanks in advance for your helpDan A couple other ways would be to do the $substring of the variable using $find index to find your start point and $text length minus $find index to cut off the first portion. Then do another $substring from 0 to $find index of the last character in the string you need. Another solution would be to load the variable as html and run $page scrape that way. Quote Link to post Share on other sites
Bot-Factory 602 Posted December 25, 2013 Author Report Share Posted December 25, 2013 Awesome! Those are some nice ideas! I'm learning something new with ubot every day! Dan Quote Link to post Share on other sites
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.