Jump to content
UBot Underground

Getting Every Nth Item In Regex


Recommended Posts

Hi I'm learning Regex but I've encountered a problem when looking at source of a page.


 


 On amazon you can see 3 monitors per line with prices. I essentially want the monitors at the start of each line which means every 1st, 4th line and so on.



https://www.amazon.com/Best-Sellers-Electronics-Computer-Monitors/zgbs/electronics/1292115011

My code is: 



(?<='true'>\n\s+)\w.*.*(?=\n\s+</div>)

How do I get every highlighted 1st, 4th, 7th, 10th line (starting at line 1 then +3) regex? 


Link to post
Share on other sites

Give this a try:

clear list(%containers)
add list to list(%containers,$scrape attribute(<class="zg_itemImmersion">,"innerhtml"),"Delete","Global")
clear list(%titles)
loop($list total(%containers)) {
    set(#container,$next list item(%containers),"Global")
    set(#title,$nothing,"Global")
    set(#title,$find regular expression(#container,"(?<=true\"\\stitle=\").*?(?=\">)"),"Global")
    if($comparison(#title,"=",$nothing)) {
        then {
            set(#title,$find regular expression(#container,"(?<=true\">).*?(?=<\\/div)"),"Global")
        }
        else {
        }
    }
    add item to list(%titles,#title,"Don\'t Delete","Global")
}

What that does is scrape the result container for each item and then looks in each for a regex that would pull the title out of the div tag if it exists and if it does not (if the title is short) then look for it in the normal place (the text of the actual link).

  • Like 1
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...