Jump to content

StringBetween and copy from source code


Lyee
 Share

Recommended Posts

Hey guys,

Need copy number from source there:

< div class = "big-number ng-binding" ng - bind = "test.currentAnswer" > 2501 < /div >

I did my code here:

Local $Input = _IETagNameGetCollection($_HB, "div")
For $i2 In $Input
    If $i2.classname == "big-number ng-binding" Then
        $Number = _StringBetween($Input, ' < div class = "big-number ng-binding" ng - bind = "test.currentAnswer" > ', ' < /div >')
    EndIf
Next

But it doesnt work and now I dont know how to copy thit string maybe _IEAction($Number,"copy") actuly dont know yet -_-

Thanks for help anyone.

Link to comment
Share on other sites

Test this script:

#include <IE.au3>
#include <MsgBoxConstants.au3>
Local $oIE = _IECreate("YourUrl")
$sHtml=_IEBodyReadHTML($oIE)
$Number = _StringBetween($sHtml, '< div class = "big-number ng-binding" ng - bind = "test.currentAnswer" > ', ' < /div >')
If IsArray($Number) Then 
    $Number = $Number[0]
Else
    $Number='not found'
EndIf
MsgBox($MB_ICONINFORMATION,'Number:',$Number)

_IEQuit($oIE)

 

Link to comment
Share on other sites

Hello,

I am currently hitting an issue like the one above however I have tried multiple ways of doing it, however every time I do it, the code fails for me.

Instead of opening a new instance of IE and reading the HTML source, I attach to an already open page and read the HTML from there. 

Once I have the HTML source, then I try read the ID's on the page into an Array, but for some reason, every time I try an example it gives me "0" or "not found" each time.

Does any of you know what I am doing wrong?

#include "Forms\Welcome.isf"
#include "Forms\Main.isf"
#include "Functions.au3"
#include "IE.au3"
#include "String.au3"
#include "Array.au3"
#include "MsgBoxConstants.au3"

Local $oIE = _IEAttach("Logged in")
$sHTML=_IEBodyReadHTML($oIE)
$PID = _StringBetween($sHTML, ',"PID":', ',"address":"')
If IsArray($PID) Then 
    $PID = $PID[0]
Else
    $PID='not found'
EndIf
ConsoleWrite($sHTML)
ConsoleWrite($PID)

Also, please note that the HTML source code is registered correctly as I can see in the console, hence the reason of writing it in the console to check.

 

Thanks,

Sep

Link to comment
Share on other sites

For safety purposes I have removed some of the data and included only one entry, however all entries have the exact same format.

Spoiler

}),
  directEventConfig: {
  isUpload: true
},
  proxy: new Ext.data.PagingMemoryProxy([{"LBID":1234,"AgentID":1234,"PID":025741963,"address":"XXXXXXXXXXX.","agreed":0,"managed":"Fully Managed","CID":11693463,"student":0,"availableFrom":new Date(1422057600000),"availableTo":new Date(1388620800000),"sendToPortals":true,"strKeyStatus":"No key available","instructed":new Date(1452698731177),"landlordName":"XXXXXXXXXX   ","VID":5853056,"propertyStyle":" (Flat)","thumbnail":"XXXXXXXXXXXXXXXXXXXX","SID":null,"percentage":20.0,"currency":"US","RentalPeriod":3,"weekPrice":1050.0,"monthPrice":4563.0,"PriceText":"Short let only","hits":0000,"rooms":10}

beforeLoadParams: function(store,options){if (!options.params){options.params = {};};Ext.apply(options.params,{});Ext.applyIf(options.params,{"limit":"10000","start":0});},
  listeners: {
  load: {
  fn: function(store,records,options){highlightFilteredCols();}
}
}
});new Ext.menu.Menu({
  id: "ctl00_ContentPlaceHolder1_mnuContext",
  items: [

 

So, for the example above, I am interested in writing 025741963

The information is at: PID":025741963,"address

 

However, for some reason, with every example and mode of doing it, I would not ever get 1 ID out of the string or even anything else from the HTML source code.

 

Edited by Arthfael
Link to comment
Share on other sites

_StringBetween is used with correct values, so maybe they are "whitespaces" in HTML. Try

#include "Forms\Welcome.isf"
#include "Forms\Main.isf"
#include "Functions.au3"
#include "IE.au3"
#include "String.au3"
#include "Array.au3"
#include "MsgBoxConstants.au3"

Local $oIE = _IEAttach("Logged in")
$sHtml=StringStripWS(_IEBodyReadHTML($oIE), $STR_STRIPALL) 
$PID = _StringBetween($sHTML, ',"PID":', ',"address":"')
If IsArray($PID) Then 
    $PID = $PID[0]
Else
    $PID='not found'
EndIf
ConsoleWrite($sHTML)
ConsoleWrite($PID)

 

Edited by AutoBert
Link to comment
Share on other sites

I just tried it and it won't work.

The HTML source code is now only the META data of the page and nothing else.

I tried to modify the following:

Local $oIE = _IEAttach("Logged in")
$sHtml=_IEBodyReadHTML($oIE)
$Number = _StringBetween($sHtml, ',"PID":', ',"address":"')
If IsArray($Number) Then 
    $Number = $Number[0]
Else
    $Number='not found'
EndIf
MsgBox($MB_ICONINFORMATION,'Number:',$Number)
ConsoleWrite($sHtml)
ConsoleWrite($Number)

But it still doesn't want to work.

I really can't figure out why the _StringBetween doesn't want to work. I have seen videos online and that where doing the same and it won't work for me at all.

Link to comment
Share on other sites

29 minutes ago, Arthfael said:

I really can't figure out why the _StringBetween doesn't want to work.

It isn't _StringBetween, as you can see it works when information is in string:

#include "String.au3"

$sHtml='The information is at: PID":025741963,"address'
$PID = _StringBetween($sHTML, 'PID":', ',"address')
If IsArray($PID) Then
    $PID = $PID[0]
Else
    $PID='not found'
EndIf
ConsoleWrite($sHTML&@CRLF)
ConsoleWrite($PID&@CRLF)

Write your HTML in a file and use a hexeditor to analyse it.

 

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

×
×
  • Create New...