Jump to content

Can AutoIt get the Page Source


Recommended Posts

  • Developers

Can I somehow get the Page Source / HTML Code of a webpage with AutoIt?

<{POST_SNAPBACK}>

isn't that what InetGet() does?

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

Well I tested that one the page I want to get the source for and it returned like 10 lines. Then I went into Mozilla, and click view page source and it was like 1000 lines...

Edit: Ok it seems to be working now...

Edited by Burrup

qq

Link to comment
Share on other sites

  • Developers

Well I tested that one the page I want to get the source for and it returned like 10 lines. Then I went into Mozilla, and click view page source and it was like 1000 lines...

<{POST_SNAPBACK}>

Do you have an example page where you see this issue with ?

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

Well I just tested it on the source for this current page, and it returned correctly. Before I tested it on a Hotmail page, which uses Javascript but even if you click Page Source in Mozilla it still wont tell you the source of the Java, I guess I compared 2 different pages.

My problem now is I want to search the source for this string...

"http://64.4.55.109/i.F424A.gif"

and tell me how many times it finds it, I can get it to search ok using StringInStr() but I dont know how to tell it to stop when it reaches the end of the file.

qq

Link to comment
Share on other sites

  • Developers

Well I just tested it on the source for this current page, and it returned correctly. Before I tested it on a Hotmail page, which uses Javascript but even if you click Page Source in Mozilla it still wont tell you the source of the Java, I guess I compared 2 different pages.

My problem now is I want to search the source for this string...

"http://64.4.55.109/i.F424A.gif"

and tell me how many times it finds it, I can get it to search ok using StringInStr() but I dont know how to tell it to stop when it reaches the end of the file.

<{POST_SNAPBACK}>

Something like:

$source = FileRead("web.txt",FileGetSize("web.txt"))
$Count = 0
While  stringInStr($source,"http://64.4.55.109/i.F424A.gif",0,$count+1)
    $count = $count + 1
WEnd
MsgBox(262144,'test','$count=' & $count )

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

  • Developers

Thanks! Works great. I dont understand the FileGetSize("web.txt") bit.

So to find out the number of lines in a text file, we can tell that by its size ?

<{POST_SNAPBACK}>

The fileread() statement will read from the file with a defined length.

So this statement reads the whole file in one statement into the variable $source.

Edited by JdeB

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

  • Developers

but...

FileRead ( filehandle or "filename", count )

count The number of characters to read.

the count is the size of the file?

<{POST_SNAPBACK}>

Count is the number of characters you want the read from the file.

So in this case: yes it is equal to its size...

Edited by JdeB

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

  • Developers

What if its not equal to the size and I want to read the whole file.

<{POST_SNAPBACK}>

Don't understand what you mean.....

FileGetSize() will always return the correct filesize.

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

  • Developers

Yes but will it always return the number of lines in the file?

<{POST_SNAPBACK}>

Reading a file with FileRead() has nothing to do with lines....

Let me try to explain:

FileReadLine() will read character until it encounters a @cr or @lf character and returns the record in a variable. So everytime you execute Filereadline($filehandle), the next record is read into the variable untill EOF is encountered at which time the @error is set.

FileRead() just looks at the file as a bunch of characters and doesn't look for @lf or @cr.

So if you for example have this code :

$variable=FileRead($filehandle,80)

Then everytime 80 characters will be read from the file into the variable until EOF is encountered.

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

I still dont get it, say the file size is 900 bytes, if i have

FileRead("web.txt",FileGetSize("web.txt"))

Each time 900 characters will be read? Is that just so that you get a 100% gaurentee that the number will be greater than the number of lines in the file?

qq

Link to comment
Share on other sites

  • Developers

I still dont get it, say the file size is 900 bytes, if i have

FileRead("web.txt",FileGetSize("web.txt"))

Each time 900 characters will be read? Is that just so that you get a 100% gaurentee that the number will be greater than the number of lines in the file?

<{POST_SNAPBACK}>

I must be my english :)

This statement will always read the whole file into $variable and normally is executed only one time.

$variable = FileRead("web.txt",FileGetSize("web.txt"))

This will read a record/line at a time till EOF is encountered:

$file = FileOpen("test.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend
FileClose($file)

This will read 80 characters at a time till eof is encountered:

$file = FileOpen("test.txt", 0)
While 1
    $line = FileRead($file,80)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend
FileClose($file)

So in your case you wanted to search the whole file for an occurrence of a given string and then its the easiest to read the whole file into a Variable and then search in that variable like i shown.......

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

I know how to use it now, but I still dont understand lol.

So if I find a file, totally non AutoIt related, a text file, that is 2 bytes big, I can say that that file is 2 lines long, just by looking at its size..

qq

Link to comment
Share on other sites

  • Developers

I know how to use it now, but I still dont understand lol.

So if I find a file, totally non AutoIt related, a text file, that is 2 bytes big, I can say that that file is 2 lines long, just by looking at its size..

<{POST_SNAPBACK}>

not 2 lines long but 2 characters long.

Like i said... Forget about lines/records with Fileread !!!!!!!!!!!!!

Fileread reads a number of characters that you specify in the second parameter!

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