Jump to content
Sign in to follow this  
Smigacznr1

Find url before string

Recommended Posts

Smigacznr1

Hi everyone

I'm trying to find youtube url from "my videos" page. HTML code looks like:

<div class="ytg-box">
          <div class="vm-video-title">
      <a href="/watch?v=1y7Q0xHz2nM" >testowanko_4</a>
        <img class="vm-video-badge" src="//s.ytimg.com/yt/img/hd_video_result_page_logo-vfl3u0IPG.png" />
  </div>

        <span class="vm-video-info">
                17 lipiec 2011, 01:07 (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>

My programm should find string "Uploaded with Free Video Converter from Freemake" and find url of video with this description. The problem is that 'testowanko_4' is the title and can be random length, source of image also and everything in link after '/watch?v=' also can be random length.

I'm sitting on that from yesterday and no idea how to do that...

I hope that everything is clear :)

Could someone help me?

Smigacznr1

Share this post


Link to post
Share on other sites
Andreik

Use _StringBetween($variable,'<a href="/watch?v=','</a>') and then use StringInStr() function to detect char > and know where start your result (in your case testowanko_4). Then a simple StringTrimLeft() or StringRight() depending on how you call StringInStr() will give you the desired result.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
dexto

It could go something like this (didn't test):

$utubeurls = StringRegExp($html, '/watch\?v=(.+?)"', 1)
If Not @error Then
    MsgBox(0, '', $utubeurls[0])
Else
    MsgBox(0, '', 'nop')
EndIf
Edited by dexto

Share this post


Link to post
Share on other sites
Smigacznr1

Thanks fo replay but it's no so simple.... In your cases functions will show all links with 'watch?=blabla' but it's not correct. On 'my videos' subpage user can have many of videos included that one without description 'Uploaded with Free Video Converter from'.

The problem is to find exactly this description and url of video with this description. In html before this kind of video and after can be videos without this description.

For now I 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 = _IEDocReadHTML ($oIE)
If $sHTML = StringRegExp('"<span class="vm-video-desc yt-uix-hovercard-target">Uploaded with Free Video Converter"', '<a href=(.*)', 1) Then

;and what now....

MsgBox(0, "title", $1HTML)
endif

Any next ideas?

Share this post


Link to post
Share on other sites
dexto

You should post a full text of the page then.

Share this post


Link to post
Share on other sites
Smigacznr1

You should post a full text of the page then.

I attached sample how 'my videos' on YouTube can look like YouTube.zip

Share this post


Link to post
Share on other sites
dexto

I attached sample how 'my videos' on YouTube can look like YouTube.zip

$html = FileRead("YouTube.htm")

$utubeid = StringRegExp($html, 'v=(.+?)"(?s)(?:.{100,1000})Uploaded with Free Video Converter from Freemake', 1)
If Not @error Then
    MsgBox(0, '', $utubeid[0])
Else
    MsgBox(0, '', 'nop')
EndIf
Edited by dexto

Share this post


Link to post
Share on other sites
Smigacznr1

$html = FileRead("YouTube.htm")

$utubeid = StringRegExp($html, 'v=(.+?)"(?s)(?:.{100,1000})Uploaded with Free Video Converter from Freemake', 1)
If Not @error Then
    MsgBox(0, '', $utubeid[0])
Else
    MsgBox(0, '', 'nop')
EndIf

Could you explain me this regex:

(?:.{100,1000}

Share this post


Link to post
Share on other sites
Smigacznr1

Mistake, sorry guys. I have to find name of video and name of edit button in code:

<div class="ytg-box">
          <div class="vm-video-title">
      <a href="/watch?v=y7dt6jK5tho" >TITLE OF VIDEO</a>
  </div>

        <span class="vm-video-info">
                17 lipiec 2011, 06:31 (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="49616900812" 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

Title in code is 'TITLE OF VIDEO' of course and

name of edit button will be '49616900812' in this case. We have to remember that title, name of button can be different for every video, we don't know length also...

Also we don't know text between name of button and title of video.

That shuld work like this:

Script search description 'Uploaded with Free Video Converter from Freemake' (that's only constant part what we know) when found is searching for video title and save in var $title, next search for name of button 'Edytuj' (html name of this button is '49616900812' in this case). Next I'll navigate by this button and do next things. I don't know how to do this search part and how to get this names...

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  

×