So I've scoured the seven seas and cannot figure this out.
Let's say I have a string of 10,000 characters. In that string there is a section I want to extrapolate; however, I don't know what it is. I only know what comes before it. Is there a way to look for a string and then copy the 10 characters after that string? For instance...
lkjsdflkjsdflkjsdflkjsdflkjdfslollerskates:roflcopter
I would find "lollerskates" and then want the "roflctoper" portion after it. The "lollerskates" part is always the same, but the characters after it change, and that's the info I want.
Grabbing text from a document Topic is solved
Grabbing text from a document
Last edited by diaewad on 25 Mar 2015, 16:04, edited 1 time in total.
Re: Grabbing text from a document
You could try RegEx
Code: Select all
str = lkjsdflkjsdflkjsdflkjsdflkjdfslollerskates:roflcopter
find = lollerskates ; initial search string
chrs = 10 ; amount of characters to search forward
RegExMatch( str, "s)" find ":(?<match>.{0," chrs "})", _ )
msgbox % _match
Re: Grabbing text from a document
I've never used RegExMatch before, so I can't seem to understand the variables used here and how to incorporate them into my script. What I need is to grab the next 4 characters after '<span id="yfs_l84_jtpy">' (reverse quoted for easier readability). I tried swapping out what you have, but it returned blank.
Code: Select all
find = <span id="yfs_l84_jtpy"> ; initial search string
chrs = 4 ; amount of characters to search forward
RegExMatch( str, "s)" find ":(?<match>.{0," chrs "})", _ )
msgbox % _match
Re: Grabbing text from a document
Nevermind! I got it. Took out the colon, and it worked. Thanks so much!
Re: Grabbing text from a document
If this is html, you're better off using an html object to get the data.
For instanceIt's easier to help if you let us know exactly what you're after in the first place.
For instance
Code: Select all
html = <span id="yfs_l84_jtpy">four</span>
HTMLObj := ComObjCreate( "HTMLfile" ), HTMLObj.write( html )
msgbox % HTMLObj.getElementsByTagName( "span" ).Item( 0 ).innerText
Re: Grabbing text from a document
Oh, I see. I thought it would be simple. Which... I guess it may be for you.
I'm trying to create an extremely minimal stock ticker for my desktop. The GUI and everything works fine, but I can't seem to get the stock price to show up. Yahoo! Finance just stopped their csv stock feed, so I'm trying to do a UrlDownloadToFile on their site and grab the stock price through their html. For instance:
Then use the script you gave me to extrapolate the price that follows '<span id="yfs_l84_%stockname%">' in the file. Although that doesn't seem to work with a variable for some reason.
I'm trying to create an extremely minimal stock ticker for my desktop. The GUI and everything works fine, but I can't seem to get the stock price to show up. Yahoo! Finance just stopped their csv stock feed, so I'm trying to do a UrlDownloadToFile on their site and grab the stock price through their html. For instance:
Code: Select all
StockName := "AAPL"
URLDownloadToFile, http://finance.yahoo.com/q?uhb=uh3_finance_vert&fr=&type=2button&s=%StockName%, C:\Stock.txt
Re: Grabbing text from a document
Try this function in your code
Code: Select all
Msgbox % GetStockPrice( "AAPL" )
GetStockPrice( Sym )
{
URL = http://finance.yahoo.com/q?uhb=uh3_finance_vert&fr=&type=2button&s=
ReqObj := ComObjCreate( "WinHttp.WinHttpRequest.5.1" ), HTMLObj := ComObjCreate( "HTMLfile" )
ReqObj.Open( "GET", URL . Sym, false ), ReqObj.Send(), HTMLObj.write( ReqObj.ResponseText )
While ( SpanObj := HTMLObj.getElementsByTagName( "span" ) ).Item( a_index-1 ).id != "yfs_l84_" Sym
Price := SpanObj.Item( a_index-1 ).InnerText
Return Price
}
Re: Grabbing text from a document
That works! You're a genius! Thanks!
Re: [SOLVED] Grabbing text from a document
unfortunatelly the code to grab a stock price no longer works:
Spoiler
any idea why? I get an error regarding the server connection.Re: [SOLVED] Grabbing text from a document
A little late in answering you, but I'm pretty sure it's because that URL is no longer valid. They've changed their site.
Re: [SOLVED] Grabbing text from a document
this fixes the issueAs a learning challenge, add error handling as it's needed.
Code: Select all
msgbox % GetStockPrice( "AAPL" )
GetStockPrice( Sym )
{
URL = http://finance.yahoo.com/quote/
ReqObj := ComObjCreate( "WinHttp.WinHttpRequest.5.1" ), HTMLObj := ComObjCreate( "HTMLfile" )
ReqObj.Open( "GET", URL . Sym, false ), ReqObj.Send(), HTMLObj.write( ReqObj.ResponseText )
QtSpObj := HTMLObj.getElementById( "quote-header-info" ).getElementsByTagName( "span" )
While !( ( Price := QtSpObj[ a_index-1 ].innerText ) ~= "^\d{1,3}[\.\d]+$" )
Continue
Return Price
}
Re: [SOLVED] Grabbing text from a document
Hi
Thanks for this TLM - it was working for a while but recently stopped working. Yahoo must have changed their code but I don't fully understand your script so can't get it working again.
Appreciate if anyone can help.
Thanks
Thanks for this TLM - it was working for a while but recently stopped working. Yahoo must have changed their code but I don't fully understand your script so can't get it working again.
Appreciate if anyone can help.
Thanks
TLM wrote: ↑22 Mar 2017, 22:24this fixes the issueAs a learning challenge, add error handling as it's needed.Code: Select all
msgbox % GetStockPrice( "AAPL" ) GetStockPrice( Sym ) { URL = http://finance.yahoo.com/quote/ ReqObj := ComObjCreate( "WinHttp.WinHttpRequest.5.1" ), HTMLObj := ComObjCreate( "HTMLfile" ) ReqObj.Open( "GET", URL . Sym, false ), ReqObj.Send(), HTMLObj.write( ReqObj.ResponseText ) QtSpObj := HTMLObj.getElementById( "quote-header-info" ).getElementsByTagName( "span" ) While !( ( Price := QtSpObj[ a_index-1 ].innerText ) ~= "^\d{1,3}[\.\d]+$" ) Continue Return Price }
Re: [SOLVED] Grabbing text from a document Topic is solved
Try this:
Code: Select all
msgbox % GetStockPrice( "AAPL" )
GetStockPrice( Sym )
{
URL = http://finance.yahoo.com/quote/
ReqObj := ComObjCreate( "WinHttp.WinHttpRequest.5.1" ), HTMLObj := ComObjCreate( "HTMLfile" )
ReqObj.Open( "GET", URL . Sym, false ), ReqObj.Send(), HTMLObj.write( ReqObj.ResponseText )
QtSpObj := HTMLObj.getElementByID( "quote-header-info" ).getElementsByTagName( "fin-streamer" )
While !( ( Price := QtSpObj[ a_index-1 ].value ) ~= "^\d{1,3}[\.\d]+$" )
Continue
Return Price
}
Re: [SOLVED] Grabbing text from a document
![Clapping :clap:](./images/smilies/icon_clap.gif)
THANK YOU!
it was the "value" on line 11 the fixed it, thanks. (I changed line 9 to "fin-streamer" but keep getting an error.
Who is online
Users browsing this forum: Google [Bot] and 378 guests