Jump to content

Getting Whipped by Strings


rezz
 Share

Recommended Posts

I've beat my head against this for 2 days and need some help.

I have a gui that has fields for name, phone, etc. It is intended to search a database by phone and return name, email, etc and put it in the form which will then log the results to notepad. The problem is getting the name from html on the page. I can view the source and see the name which changes with each customer.

I try to use stringbetween and get the unknown name but its not working in any way I have tried.

Here's what I have at the moment:

_IELoadWait($oIE)
$sURL2 = _IEPropertyGet($oIE, "locationurl")
ClipPut($sURL2)
$sHTML = _IEBodyReadHTML ($sURL2)

;$MyString1 = "<span id=""DetailView1_lblFName""></span>"
;~ $StartStr1 = "<span id=""DetailView1_lblFName"">"
;~ $EndStr1 = '</span>'
$Results = _StringBetween("", "<span id=""DetailView1_lblFName"">", "</span>")
$NameFirst = _ArrayToString($Results, "", 1, "")
ClipPut($NameFirst)

The first clipput() gets the page url ok.

The second clipput shows nothing at all even if I disable the unneeded first clipput.

How can I get the string between:

<span id=""DetailView1_lblFName"">

and

</span>

and put to clip??

Once I have the name I then want to place it in my GUI in the field for name.

I am currently trying to use:

$Name= GUICtrlCreateInput(ClipGet(), 80, 50, 110, 20)

That would work but there is probably a better way.

Any help would be appreciated. I'm new and still learning but am stuck here.

Cannot post the page source. It is a confidential database. The needed name is clearly visible on the source though.

Link to comment
Share on other sites

  • Developers

what is the first parameter supposed to be:?

$Results = _StringBetween("", "<span id=""DetailView1_lblFName"">", "</span>")

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

The first param that is on either side of the unknown name is:

<span id=""DetailView1_lblFName"">

The 2nd is:

</span>

_StringBetween returns the first match in element [0]

You are using _ArrayToString starting from element 1 ...

I'll leave the conclusion to you :graduated:

The unknown name is in between the 2.

I tried changing the arraytostring to 1 but the clipboard remains empty.

Link to comment
Share on other sites

  • Developers

The first param that is on either side of the unknown name is:

<span id=""DetailView1_lblFName"">

The 2nd is:

</span>

So why do you have "" as first parameter in StringBetween() ??

Update your posted code snipped with the suggested changes and when it doesn't work show what you changed it to.

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

#Include <String.au3>
#Include <Array.au3>

$string = '<span id=""DetailView1_lblFName"">STRINGBETWEEN</span>'

$Results = _StringBetween($string, '<span id=""DetailView1_lblFName"">', '</span>')

_ArrayDisplay ($Results)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

#Include <String.au3>
#Include <Array.au3>

$string = '<span id=""DetailView1_lblFName"">STRINGBETWEEN</span>'

$Results = _StringBetween($string, '<span id=""DetailView1_lblFName"">', '</span>')

_ArrayDisplay ($Results)
Note the awkward use of doubled-double-quotes inside double-quotes in the OP's example. To reduce the confusion, perhaps:
#Include <String.au3>
#Include <Array.au3>

$string = '<span id="DetailView1_lblFName">STRINGBETWEEN</span>'

$Results = _StringBetween($string, '<span id="DetailView1_lblFName">', '</span>')

_ArrayDisplay ($Results)

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is the actual page code that I need to search:

<span id="DetailView1_lblFName">UNKNOWNNAME</span>

I just tried this:

$Results = _StringBetween("<span id=""DetailView1_lblFName"">", "", "</span>")
$NameFirst = _ArrayToString($Results, "", 1, 1)
ClipPut($NameFirst)
_ArrayDisplay ($Results)

and get nothing as a result.

When I use this:

$string = '<span id=""DetailView1_lblFName"">STRINGBETWEEN</span>'

$Results = _StringBetween($string, '<span id=""DetailView1_lblFName"">', '</span>')

_ArrayDisplay ($Results)

The display is: STRINGBETWEEN

Same result from PsaltyDS's version.

I am missing something simple probably but at this point confusion has set in.

Link to comment
Share on other sites

The second parameter of your _StringBetween() is an empty string "", which means start at beginning of string, then the third parameter is "</span>", which doesn't exist in the input string of "<span id=""DetailView1_lblFName"">" (you trimmed the end off it).

That's why you get nothing.

:graduated:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well, I see I have to explain it .../sigh

- _StringBetween returns first match in element [0]

- you were converting _ArrayToString starting with element [1]

Conclusion: you were missing the [0] element - you need to change _ArrayToString($Results, "", 1, "") either to _ArrayToString($Results, "",0 , "") or _ArrayToString($Results, "") in order to get your first match.

There are a few more problems as Jos and PsaltyDS have said which will need to be resolved; my solution was adressing only one aspect.

And here is a script to test:

#Include <String.au3>
#Include <Array.au3>

$string = '<span id="DetailView1_lblFName">UNKNOWNNAME</span>'
$result = _StringBetween($string, '<span id="DetailView1_lblFName">', '</span>')

MsgBox(0, "using 1", _ArrayToString($result, "", 1))
MsgBox(0, "using 0", _ArrayToString($result, ""))
Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

$sResult = StringRegExpReplace($sHTML, "(?i)<span\s*id=\x22?DetailView1_lblFName\x22?>(.+)</span>", $1)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks to everyone for your help.

I got it working thanks to you guys and after I figured out another issue that was causing problems.

The page I was trying to get the string from had the info in an iframe.

I ended up avoiding learning how to access the iframe by waiting for the next page to load. It also had the needed info.

Here's what worked:

_IELoadWait($oIE)
$sHTML = _IEDocReadHTML ($oIE)
$avNameFirst = _StringBetween($sHTML, "DetailView1_lblFName>",  "</span>")
$NameFirst = _ArrayToString($avNameFirst)
$avNameLast = _StringBetween($sHTML,"DetailView1_lblLName>", "</span>")
$NameLast = _ArrayToString($avNameLast)
$Name = GUICtrlCreateInput($NameFirst & " " & $NameLast, 80, 50, 110, 20)

This retrieves the needed info and puts it in my GUI form field by using the last line.

Is there a better way I can get the data to the gui input field?

The current method actually rewrites the gui code and I wonder if this might have a negative effect that I haven't noticed yet.

Now to figure out how to get IE to open a new tab instead of opening a new window or using the existing tab.

I'm in over my head with Autoit but want to learn as much as I can while creating tools to accomplish needed tasks.

Thanks again.

Link to comment
Share on other sites

rezz,

You can set the data of the input with GUICtrlSetData()

Local $ui = GUICreate("Example", 300, 200)
Local $Name = GUICtrlCreateInput("", 80, 50, 110, 20)
GUISetState(@SW_SHOW, $ui)

_SetData()

Do
Until GUIGetMsg() = -3

GUIDelete($ui)

Func _SetData()
    Local $NameFirst = "First", $NameLast = "Last"
    GUICtrlSetData($Name, $NameFirst & " " & $NameLast)
EndFunc

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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