Stripping quotes and ; from html

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.

Stripping quotes and ; from html

by christinapitt76 on Thu Sep 29, 2016 7:04 am

Hello all,
took me a couple days to figure this out so thought I would share:

text imacros extracted
Code: Select all
<span content="sku:17508782" itemprop="productID" style="outline: 1px solid blue;"></span>


what I actually wanted
Code: Select all
17508782


what I used to get it
Code: Select all
SET !EXTRACT NULL 
'Reseting extract to null, then giving the item number in html
TAG POS=R1 TYPE=SPAN ATTR=content:sku* EXTRACT=HTM
SET myVarA EVAL("var a=\"{{!EXTRACT}}\"; a.replace(/\"/g, \"\");")
'PROMPT  Variable<SP>Var4:<SP><SP>{{myVarA}}
SET myVarB EVAL("var b=\"{{myVarA}}\"; b.replace(/;/g, \"\");") 
SET myVarC EVAL("var c=\"{{myVarB}}\"; c.replace(\"<span content=sku:\");") 
SET myVarD EVAL("var d=\"{{myVarC}}\"; d.replace(\" itemprop=productID style=outline: 1px solid blue></span>\",\"\");") 
SET itemNumb EVAL("var e=\"{{myVarD}}\"; e.replace(\"undefined\",\"\");")     
'PROMPT  Variable<SP>itemNumb:<SP><SP>{{itemNumb}}


hope this is useful to someone else, prompts aren't necessary, I just used them when hacking out a solution
christinapitt76
 
Posts: 6
Joined: Wed Nov 11, 2015 11:58 am

Re: Stripping quotes and ; from html

by chivracq on Thu Sep 29, 2016 4:39 pm

christinapitt76 wrote:Hello all,
took me a couple days to figure this out so thought I would share:

text imacros extracted
Code: Select all
<span content="sku:17508782" itemprop="productID" style="outline: 1px solid blue;"></span>


what I actually wanted
Code: Select all
17508782


what I used to get it
Code: Select all
SET !EXTRACT NULL 
'Reseting extract to null, then giving the item number in html
TAG POS=R1 TYPE=SPAN ATTR=content:sku* EXTRACT=HTM
SET myVarA EVAL("var a=\"{{!EXTRACT}}\"; a.replace(/\"/g, \"\");")
'PROMPT  Variable<SP>Var4:<SP><SP>{{myVarA}}
SET myVarB EVAL("var b=\"{{myVarA}}\"; b.replace(/;/g, \"\");") 
SET myVarC EVAL("var c=\"{{myVarB}}\"; c.replace(\"<span content=sku:\");") 
SET myVarD EVAL("var d=\"{{myVarC}}\"; d.replace(\" itemprop=productID style=outline: 1px solid blue></span>\",\"\");") 
SET itemNumb EVAL("var e=\"{{myVarD}}\"; e.replace(\"undefined\",\"\");")     
'PROMPT  Variable<SP>itemNumb:<SP><SP>{{itemNumb}}


hope this is useful to someone else, prompts aren't necessary, I just used them when hacking out a solution

Very good...! (well, I didn't test your Code...), and nice of you indeed to share your Solution...! :D
You should still mention your FCI btw as an Indication in which FCI you've tested it..., many Commands are not implemented or get broken for/from all/a (specific) Browser(s)/Version(s)...

You can achieve what you want in just one Statement as well, using 'split()' x2 instead of all your 'replace()':
Code: Select all
SET !EXTRACT NULL 
'Reseting extract to null, then giving the item number in html
TAG POS=R1 TYPE=SPAN ATTR=content:sku* EXTRACT=HTM
'=> Extracted: <span content="sku:17508782" itemprop="productID" style="outline: 1px solid blue;"></span>
'=> Want to keep: 17508782

SET itemNumb EVAL("var s='{{!EXTRACT}}'; var y,z; y=s.split(':'); z=y[1].split('"'); z[0];")     
PROMPT  Variable<SP>itemNumb:<SP><SP>_{{itemNumb}}_
(Not tested...)
- (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: 6484
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: Google [Bot], Yahoo [Bot] and 4 guests

cron
-->