Jump to content
Sign in to follow this  
faustf

regexp help

Recommended Posts

hi guys  i try to cacth a number mq  of  this  page web

https://www.casa.it/srp/?page=1&tr=vendita&category=residenziale&surrounding=false&geopolygon={"polygon":[[43.843557448900775,10.489038304546511],[43.84241221396654,10.4942954342157],[43.84258245298302,10.494424180248415],[43.84313959545863,10.493694619396365],[43.84496574820621,10.495239571788943],[43.84621926137939,10.492643193462527],[43.846559717198694,10.491162614086306],[43.845894279011965,10.490411595562136],[43.84573178716427,10.488995389202273],[43.84573952488136,10.4888022701532]],"bbox":[[43.8481226939768,10.48334129259888],[43.84084908756247,10.500700549343264]],"zoom":17}&precision=8

i want  all  mq.  of this page  90   ,  300 , .....  etc

i try to cacth with this code

Local $aLSuperfice = StringRegExp($sLHtmlPage, ' -->([0-9]+)<!-- \/react-text --><!-- react-text: .+? --> <!-- \/react-text --><span>mq<', 3)

but return me 14  , 5  and many number but nothing  about mq , whats wrong in regexp ??  i  identify  mq  with  <span>mq<' 

some one can help me ??  thankz

(for create a regexp)

Share this post


Link to post
Share on other sites

You might first remove all the "<...>" parts, so the result will be much easier to treat
Example

$s = '<p data-reactid="202">Appartamento</p></div><div class="features" data-reactid="203"><p data-reactid="204"><!-- react-text: 205 -->€ <!-- /react-text --><!-- react-text: 206 -->79.000<!-- /react-text --><span data-reactid="207"><!-- react-text: 208 -->Tua da <!-- /react-text --><span class="asStrong" data-reactid="209"><!-- react-text: 210 -->€ <!-- /react-text --><!-- react-text: 211 -->261<!-- /react-text --></span><!-- react-text: 212 -->/mese<!-- /react-text --></span></p><ul data-reactid="213"><li data-reactid="214"><!-- react-text: 215 -->55<!-- /react-text --><!-- react-text: 216 --> <!-- /react-text --><span data-reactid="217">mq</span></li><li data-reactid="218">'

$r = StringRegExpReplace($s, '<.*?>', "")
Msgbox(0,"", $r)

 

Share this post


Link to post
Share on other sites

i'd like to see this in one big regex, but as best i can determine

- find the reactid for 'mq'

- get the value at the location "react-text:  [reactid minus 2]"

*2 bonus mq entries at the end need to be cleaned up, i brute force them with pop

#include <Inet.au3>
#include <Array.au3>

$sHTM = 'https://www.casa.it/srp/?page=1&tr=vendita&category=residenziale&surrounding=false&geopolygon=%7B'

$s = BinaryToString(InetRead($sHTM))

$a = StringRegExp($s , 'reactid="(\d+)">mq<' , 3)
_ArrayPop($a)
_ArrayPop($a)

for $i = 0 to ubound($a) - 1
    $a[$i] =  stringregexp($s , 'react-text: ' & $a[$i] - 2 & ' -->(.*?)<' , 3)[0] & 'mq'
Next


_ArrayDisplay($a)

 

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Try this:

Local $u = 'https://www.casa.it/srp/?page=1&tr=vendita&category=residenziale&surrounding=false&geopolygon={"polygon":[[43.843557448900775,10.489038304546511],[43.84241221396654,10.4942954342157],[43.84258245298302,10.494424180248415],[43.84313959545863,10.493694619396365],[43.84496574820621,10.495239571788943],[43.84621926137939,10.492643193462527],[43.846559717198694,10.491162614086306],[43.845894279011965,10.490411595562136],[43.84573178716427,10.488995389202273],[43.84573952488136,10.4888022701532]],"bbox":[[43.8481226939768,10.48334129259888],[43.84084908756247,10.500700549343264]],"zoom":17}&precision=8'
Local $s = BinaryToString(InetRead($u))

Local $f = _TempFile(".\")
Local $h = FileOpen($f, $FO_OVERWRITE)
$s = '"Price €","Rent €","Area m²","Rooms","Parking"' & @CRLF & _
    StringRegExpReplace($s, _
    '(?sx)' & _
    '(?: .*? < div\ class="features" [^<]*? > )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* ( \d+ ) . ( \d+ )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* ( \d+ ) .? ( \d* )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* ( \d+ )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* ( \d+ )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* ( \d* )' & _
    '(?: < [^<]*? > )* (?: [^<]* )' & _
    '(?: < [^<]*? > )* (?: <\/div> .*? (?= <div\ class="features" | $ ) )', _
    "$1$2, $3$4, $5, $6, $7" & @CRLF)
FileWrite($h, $s)
FileClose($h)

Local $a
_FileReadToArray($f, $a,$FRTA_NOCOUNT, ',')
FileDelete($f)
_ArrayDisplay($a)

Beware, such parsing may break when the site decide to change its format!


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...