Jump to content
Sign in to follow this  
Smigacznr1

Stringbetween and regex problem

Recommended Posts

Smigacznr1

In code:

<a href="/watch?v=GcOAv1M3Kn8" >flower_trans_RGB_PAL</a>
  </div>

        <span class="vm-video-info">
                18 lipiec 2011, 02:24 (PDT)

            <span class="vm-separator">|</span>
                <div class="yt-uix-hovercard vm-inline">
        <span class="vm-video-desc yt-uix-hovercard-target">Uploaded with Free Video Converter from Freemake
http://www.fr...</span>
        <span class="yt-uix-hovercard-content">Uploaded with Free Video Converter from Freemake
http://www.freemake.com/free_video_converter/</span>
      </div>

        </span>
        <span class="vm-video-info">
        </span>
            <span class="vm-video-info">
      

      

      

        


      <span class="yt-uix-button-group"><button name="66447398811" onclick=";return false;" type="button" class="start vm-playlist-edit-video yt-uix-button yt-uix-button-short"  role="button" aria-pressed="false"><span class="yt-uix-button-content">Edytuj</span></button>

I need to find title (flower_trans_RGB_PAL). I have:

$tytul = _StringBetween($sHTML,'" >','</a>([?s]*)Uploaded with Free Video Converter')

and it's getting me empty string. I don't know why.

?s - all chars with new line

* - repeating

What's wrong?

Share this post


Link to post
Share on other sites
jchd

You're confusing _StringBetween and StringRegExp!

Read help file again for these two functions.

Then your vision of regexp patterns is poetic at best and doesn't fit PCRE Regular Expression semantic.

Try:

$res = StringRegExp($html, ">([^<]*?)</a>", 3)

EDIT: right, the cut & paste went astray. Sorry

Edited by jchd

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
Smigacznr1

try it:

$ary = StringRegExp($sHTML,'<a href="/watch\?v=.*?" >(.*?)</a>',3)
for $i = 0 to UBound($ary) - 1
    msgbox(0, "RegExp", $ary[$i])
Next

Don't work. No msgbox...

I'm lost now.

Could someone write this whole function?

I'm learning autoit for few days. I'm learning best on samples so I'll be grateful for whole function.

I have no idea how to do that. :/

Share this post


Link to post
Share on other sites
jchd

This works on the example you gave:

$shtml = '  ...  whatever before  ...  <a href="/watch?v=GcOAv1M3Kn8" >flower_trans_RGB_PAL</a>  ...  whatever follows  ...  '
$ary = StringRegExp($sHTML, '<a href="/watch\?v=.*?" >(.*?)</a>', 3)
For $i = 0 To UBound($ary) - 1
    msgbox(0, "RegExp", $ary[$i])
Next

Now if your actual data departs from your example, then the pattern may have to be adjusted.


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
Smigacznr1

This works on the example you gave:

$shtml = '  ...  whatever before  ...  <a href="/watch?v=GcOAv1M3Kn8" >flower_trans_RGB_PAL</a>  ...  whatever follows  ...  '
$ary = StringRegExp($sHTML, '<a href="/watch\?v=.*?" >(.*?)</a>', 3)
For $i = 0 To UBound($ary) - 1
    msgbox(0, "RegExp", $ary[$i])
Next

Now if your actual data departs from your example, then the pattern may have to be adjusted.

With your example I have no msgbox...

What I need exactly to do. I need to check if in HTML is description "Uploaded with Free Video Converter" if yes check what is name of video with above description and find name of button 'Edytuj' (html code I posted first on this topic).

And here is some difficult because we don't know leght of code between title of video and description and between description and name of button 'Edytuj'.

Only one constant string what we know always is part of description ('Uploaded with Free Video Converter').

That's why it's so hard for me. I'm trying to write something like this for first time and I stuck... :/

I already have:

Func zamykanie()
    if $success = True Then
        $oIE = _IECreate ("https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Dpl_PL%26next%3D%252F&hl=pl_PL&ltmpl=sso", 0, 1, 1, 0)
        Send("login{TAB}pass{ENTER}")
        _IELoadWait ($oIE)
        _IENavigate ($oIE, "http://www.youtube.com/my_videos?feature=mhee")
        _IELoadWait ($oIE)
        $sHTML = _IEBodyReadHTML ($oIE)

If StringInStr($sHTML,"Uploaded with Free Video Converter") Then

;something to do here

endif


EndFunc

Share this post


Link to post
Share on other sites
jchd

I insist on being positive: with the untouched example the msgbox pops up.


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
Smigacznr1

I insist on being positive: with the untouched example the msgbox pops up.

#include <IE.au3>
#Include <String.au3>
#Include <Array.au3>
AutoItSetOption("WinTitleMatchMode", 2)
Global $success = False

completed()

Func completed()
    $i=0
        For $i=0 to 1
            If WinExists("Uploading completed") Then
                If WinExists("Success") Then
                    $success = True
                    zamykanie()
                endif
            endif
        $i=0
        ContinueLoop
        next
EndFunc

Func zamykanie()
    if $success = True Then
        $oIE = _IECreate ("https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Dpl_PL%26next%3D%252F&hl=pl_PL&ltmpl=sso", 0, 1, 1, 0)
        Send("login{TAB}pass{ENTER}")
        _IELoadWait ($oIE)
        _IENavigate ($oIE, "http://www.youtube.com/my_videos?feature=mhee")
        _IELoadWait ($oIE)
        $sHTML = _IEBodyReadHTML ($oIE)

If StringInStr($sHTML,"Uploaded with Free Video Converter") Then
$ary = StringRegExp($sHTML, '<a href="/watch\?v=.*?" >(.*?)</a>', 3)
For $i = 0 To UBound($ary) - 1
    MsgBox(0, "RegExp", $ary[$i])
Next

endif

EndFunc

So what's wrong here?

Share this post


Link to post
Share on other sites
jchd

Your URL!

Add COM error function.


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
Smigacznr1

Your URL!

Add COM error function.

OK. I'm reading about COM and objactions. Coul you tell which url is wrong and why?

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  

×