Jump to content

Recommended Posts

Posted

Alright, so I have this website with radio dramas that are updated weekly, where one is added and one is removed. So, I know the number of episodes there will be.

I created a script to pull the links, but my problem is I can tell how long the script is going to be the way I am going to do it.

Here's what I have:

#include <IE.au3>

Global $Count

$file = "Linkss.txt"

$oIE = _IECreate ("http://www.oneplace.com/ministries/paws-and-tales/listen/broadcast-archives.html")
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
For $oLink In $oLinks
    $Count += 1
    If $Count = 23 Then
        FileWriteLine($file, $oLink.href)
    EndIf
    If $Count = 24 Then
        FileWriteLine($file, $oLink.href)
        EndIf
Next

So, the way I know how to do it I am going to need to write 52 If statements. And that is going to take a lot of space and I'm sure theres a better/cleaner way to do this.

I am going to look into atm, but I was wondering if anyone could lend a hand to make it go quicker!

Thanks!

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Posted (edited)

I'm not sure exactly what you mean, but it looks like these 2 lines are exactly the same:

If $Count = 23 Then

FileWriteLine($file, $oLink.href)

EndIf

If $Count = 24 Then

FileWriteLine($file, $oLink.href)

EndIf

If these are the lines you are going to repeat, just incrimenting (24, 25, 26 etc.) 52 times, then why not a single line that says

If $Count > 22 Then

FileWriteLine($file, $oLink.href)

EndIf

*edit to include 23 in the if statement*

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Posted (edited)

Is this short enough for you?

#include <file.au3>
_FileWriteFromArray("Linkss.txt",StringRegExp(BinaryToString(InetRead("http://www.oneplace.com/ministries/paws-and-tales/listen/broadcast-archives.html")),'(?i)(?s)<h5><a href="(.*?)">',3))

Couldn't resist. This would have been usefull in the other topic btw. It allows you to properly get the titles.

Edit:

This will add any links that are not in the file yet to the existing file:

#include <array.au3>
#include <file.au3>
Global $aFile, $aLinks
Global $sFilePath, $sSource
$sFilePath = "Linkss.txt"
$sSource = BinaryToString(InetRead("http://www.oneplace.com/ministries/paws-and-tales/listen/broadcast-archives.html")) ;download the page source
$aLinks = StringRegExp($sSource,'(?i)(?s)<h5><a href="(.*?)">',3) ;put all matching links in an array
If Not IsArray($aLinks) Then ;check if links where found
    MsgBox(0,"error","No links found!")
    Exit
EndIf
_FileReadToArray($sFilePath,$aFile) ;load the file you already have
If IsArray($aFile) Then ;check if anything is loaded
    For $i = 0 To UBound($aLinks) -1 ;loop through each link in the array
        _ArraySearch($aFile,$aLinks[$i],1) ;check if it already exists
        If @error = 6 Then ;if the link was not found in the file array
            _ArrayAdd($aFile,$aLinks[$i]) ;add the link to the file array
        EndIf
    Next
    _FileWriteFromArray($sFilePath,$aLinks,1) ;write the new array back to the file
Else
    _FileWriteFromArray($sFilePath,$aLinks) ;if there is no file array, create the file with the links we found
EndIf
Edited by Tvern

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
  • Recently Browsing   0 members

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