Jump to content

get html data using StringRegExp


Recommended Posts

hello everybody 

I have this html code and wanna get some data using autoit especially 

<h3 itemprop="name" class="entry-title"><a itemprop="url" href="http://www.mywebsite.com/1/" rel="bookmark" title="hello world 1</a></h3>

<h3 itemprop="name" class="entry-title"><a itemprop="url" href="http://www.mywebsite.com/2/" rel="bookmark" title="hello world 2</a></h3>

I need to get the URLs and their titles 

in php I can do this 

$data= file_get_contents($url);
$re= '/<h3 itemprop="name" class="entry-title"><a itemprop="url" href="(.*?)" rel="bookmark" title="(.*?)<\/a><\/h3>/s';
preg_match($re, $data, $match);     
preg_match_all($re,$data,$match);

but I can't do this in autoit 

please help 

Edited by AlienStar
Link to comment
Share on other sites

I didn't post earlier as you said you wanted Regex. However, if you're willing to use https://www.autoitscript.com/autoit3/docs/libfunctions/_IECreate.htm

Then you can try using something like this (not tested):

Local $h3Tags = _IETagNameGetCollection($ie, "h3")

For $h3Tag In $h3Tags
    Consolewrite(_IEPropertyGet($h3Tag, "InnerText") & @CRLF)
    Consolewrite(_IEPropertyGet($h3Tag, "InnerHTML") & @CRLF)
    Consolewrite($h3Tag.Title & @CRLF)
Next

Edit: Whoops, sorry. I just realised Juvigy isn't the OP.

Edited by IAMK
Link to comment
Share on other sites

6 hours ago, IAMK said:

I didn't post earlier as you said you wanted Regex. However, if you're willing to use https://www.autoitscript.com/autoit3/docs/libfunctions/_IECreate.htm

Then you can try using something like this (not tested):

Local $h3Tags = _IETagNameGetCollection($ie, "h3")

For $h3Tag In $h3Tags
    Consolewrite(_IEPropertyGet($h3Tag, "InnerText") & @CRLF)
    Consolewrite(_IEPropertyGet($h3Tag, "InnerHTML") & @CRLF)
    Consolewrite($h3Tag.Title & @CRLF)
Next

Edit: Whoops, sorry. I just realised Juvigy isn't the OP.

 

thanks so much you gave me the idea to continue :)

Edited by AlienStar
Link to comment
Share on other sites

15 hours ago, AlienStar said:

but I can't do this in autoit 

There is a lot of snippets on this forum about this, with examples
BTW If php can do it, then AutoIt can too  -_-

#Include <Array.au3>

$txt = '<h3 itemprop="name" class="entry-title"><a itemprop="url" href="http://www.mywebsite.com/1/" rel="bookmark" title="hello world 1</a></h3>' & @crlf & _ 
    '<h3 itemprop="name" class="entry-title"><a itemprop="url" href="http://www.mywebsite.com/2/" rel="bookmark" title="hello world 2</a></h3>'
; Msgbox(0,"", $txt)

$res = StringRegExp($txt, '(?:href|title)="([^"<]+)', 3)
_ArrayDisplay($res)

 

Link to comment
Share on other sites

1 hour ago, mikell said:

There is a lot of snippets on this forum about this, with examples
BTW If php can do it, then AutoIt can too  -_-

#Include <Array.au3>

$txt = '<h3 itemprop="name" class="entry-title"><a itemprop="url" href="http://www.mywebsite.com/1/" rel="bookmark" title="hello world 1</a></h3>' & @crlf & _ 
    '<h3 itemprop="name" class="entry-title"><a itemprop="url" href="http://www.mywebsite.com/2/" rel="bookmark" title="hello world 2</a></h3>'
; Msgbox(0,"", $txt)

$res = StringRegExp($txt, '(?:href|title)="([^"<]+)', 3)
_ArrayDisplay($res)

 

Amazing :lmao::lmao:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...