Sign in to follow this  
Followers 0
AuToItItAlIaNlOv3R

String Help

9 posts in this topic

#1 ·  Posted (edited)

Greetings to all forum, i've a problem! I wold link to capture a line in a html source file. For explample i've write this code

$oIE = _IECreate("http://xxxxxxxxxxxxxxxx)
$Sourcecode = _INetGetSource($oIE)
FileWrite ("C:\sourcecode.txt", $Sourcecode)
$readtext = FileRead("C:\sourcecode.txt")
$array = _StringBetween($readtext,"</SPAN><B>","</B><SPAN class=m>")
FileWrite ("C:\capturedline.txt", $array)

In sourcecode.txt i would to capture the text in bold

<SPAN class=m>="</SPAN><B>http:xxxxxxxxx</B><SPAN class=m>"</SPAN><SPAN class=m> /&gt;</SPAN> </DIV>

I wold to capture the bold links (http:xxxxxxxx) but with my code the file C:\capturedline.txt

Is empty!...help me!

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

This a piece of script that collects all text from Boldtags.

In this example from Google.

#include <IE.au3>
#include <INet.au3>
#Include <string.au3>

$oIE = _IECreate("http://www.google.com")
$oBolds = _IETagNameGetCollection($oIE, "B")
    For $oBold in $oBolds
        $Sourcecode = ($oBold.innertext) & @CRLF
        ;MsgBox(1, "", $Sourcecode) ;to test things out
        FileWrite ("C:\capturedline.txt", $Sourcecode) ; to write to file
    Next

Rick

Edited by Rkey

Share this post


Link to post
Share on other sites

@Rkey

I wolud like to captured a line in a html source code...your script is not good for my needs.

Thanks for all :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Greetings to all forum, i've a problem! I wold link to capture a line in a html source file. For explample i've write this code

$oIE = _IECreate("http://xxxxxxxxxxxxxxxx) 
$Sourcecode = _INetGetSource($oIE)
FileWrite ("C:\sourcecode.txt", $Sourcecode)
$readtext = FileRead("C:\sourcecode.txt")
$array = _StringBetween($readtext,"</SPAN><B>","</B><SPAN class=m>")
FileWrite ("C:\capturedline.txt", $array)

In sourcecode.txt i would to capture the text in bold

<SPAN class=m>="</SPAN><B>http:xxxxxxxxx</B><SPAN class=m>"</SPAN><SPAN class=m> /&gt;</SPAN> </DIV>

I wold to capture the bold links (http:xxxxxxxx) but with my code the file C:\capturedline.txt

Is empty!...help me!

I don't think you can Write an array to a file in that manner, you would really need something like this

#Include <Array.au3> ;include
#Include <string.au3> ;include
;$oIE = _IECreate("http://xxxxxxxxxxxxxxxx")  ;don't really need this
$Sourcecode = _INetGetSource("http://xxxxxxxxxxxxxxxx")
;FileWrite ("C:\sourcecode.txt", $Sourcecode) ;don't really need this
;$readtext = FileRead("C:\sourcecode.txt") ;don't really need this
$array = _StringBetween($Sourcecode,"</SPAN><B>","</B><SPAN class=m>")
$sOutput = _ArrayToString($array, @CRLF) ;make the array 1 whole string separated by the CR and LF
FileWrite ("C:\capturedline.txt", $sOutput) ; write the string out

hope that helps, I didn't run it but it should work like that.

Edit: double checked the rest of code

Edited by nekkutta

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

nekkutta your script don't work. The capturedline.txt is empty :)

Please help!

Edit: I changed the script, but non the new file contain this :

"http://xxxxx"

Now i would like to remove " in the link...how i do it?...

I tried with

StringReplace ("C:capturedline.txt","''","")

But it don't work, how i do it?

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
Share on other sites

You make a few assumptions that are not correct. Read the help file carefully to see what a function returns and expects. For example, StringReplace("C:\capturedline.txt", "''", "") is not correct and would just execute on this generic string which is not what you want. In short, read the help file. :)

Share this post


Link to post
Share on other sites

I already read the help file, but i don't find anything read anything about how to replace the ". :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Logic plays a major part while developing or solving a problem. I guess that it's sufficient to post a hint but it won't be useful if you won't read the help file carefully. To change a file content you need to read it, i.e. open the file using the appropriate way (read the last parameter of FileOpen), modifying the file content using the string manipulation functions, write the modified string back to the file and close it.

..or a simple way, before you write to the file, replace any occurrences of " on the string and write this new string to the file.

Another way, is to match and capture only the data you want, either by the StringRegExp() function or the _StringBetween() function. Sorry for long boring post.

Edit: You may also want to take a look in the help file in the "Datatypes" section because these are the basics.

Edited by Authenticity

Share this post


Link to post
Share on other sites

Look up "StringReplace" in the help file.. it doesn't say to use a file path...

StringReplace ( "string", "searchstring" or start, "replacestring" [, count [, casesense]] )

So.. not

StringReplace ("C:capturedline.txt","''","")

but..

$Read = FileRead ('C:\capturedline.txt')
$New = StringReplace ($Read, '"','')
FileDelete ('C:\capturedline.txt')
FileWrite ('C:\capturedline.txt', $New)

Next time read the help file a bit closer.., Hope this helps!

- John :)


Latest Projects :- New & Improved TCP Chat

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  
Followers 0