Jump to content
Sign in to follow this  
t11wright

txt file read line by line

Recommended Posts

t11wright
Func Start()

while 1

$file = "youtube.txt"
FileOpen($file, 0)

For $i = 1 to _FileCountLines($file)
$line = FileReadLine($file, $i)

$NewURL = ClipPut($line)
$NewURL = ClipGet()

Local $oIE = _IECreate($NewURL)
_IELoadWait($oIE)
Local $oDiv = _IEGetObjById($oIE, "eow-title")
_IEQuit($oIE)

$file = FileOpen("youtubetitles.txt", 1)
FileWrite($file, $oDiv.innertext & @CRLF)
FileClose($file)

WEnd
EndFunc

youtube.txt has 3 lines of youtube adresses.. With this script I can only find youtube title of first line. Want to find second and third title too. Can you please help me ?

Share this post


Link to post
Share on other sites
Jos

Your code is quite messy when it comes to the use of the variable $file. It is both used as the original input filename and the output filehandle!
What is the ClipPut & Clipget for?

This should be close but is untested!

Func Start()

    $file = "youtube.txt"
    $fhi = FileOpen($file, 0)
    If @error Then Return 0 
    $fho = FileOpen("youtubetitles.txt", 1)
    While 1
        $line = FileReadLine($fhi)
        If @error Then ExitLoop ; EOF encountered
;~  What is this for?
;~      $NewURL = ClipPut($line)
;~      $NewURL = ClipGet()

        Local $oIE = _IECreate($NewURL)
        _IELoadWait($oIE)
        Local $oDiv = _IEGetObjById($oIE, "eow-title")
        FileWrite($fho, $oDiv.innertext & @CRLF)
        _IEQuit($oIE)

    WEnd
    FileClose($fhi)
    FileClose($fho)
    return 1
EndFunc   ;==>Start

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
t11wright

Thanks for your code!!

I had to define $NewURL as Global and now it works!

$NewURL = ClipPut($line)
$NewURL = ClipGet()

without these lines opens an empty IE page.

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  

×