Jump to content

txt file read line by line


Recommended Posts

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 ?

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...