Jump to content



Photo

Getting Every Nth Item In Regex

regex

  • Please log in to reply
4 replies to this topic

#1 Dallashox

Dallashox

    Member

  • Members
  • PipPip
  • 17 posts
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.5+, unsure
  • License:Standard Edition

Posted 17 July 2017 - 07:20 PM

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? 



#2 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 3202 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 18 July 2017 - 02:29 PM

What are you trying to get the title or link or what?



#3 Dallashox

Dallashox

    Member

  • Members
  • PipPip
  • 17 posts
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.5+, unsure
  • License:Standard Edition

Posted 19 July 2017 - 10:33 PM

The title



#4 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 3202 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 20 July 2017 - 12:42 PM

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



#5 Dallashox

Dallashox

    Member

  • Members
  • PipPip
  • 17 posts
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.5+, unsure
  • License:Standard Edition

Posted 21 July 2017 - 06:29 AM

Thanks man







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users