sammy1983 Posted January 13, 2014 Posted January 13, 2014 Hi, I am working on a project where I save data in excel after extracting from a webpage. I have a Textbox in the webpage where there is string containing Uppercase letters and few digits. Example: (PM1153125) Incorrect Amounts reflecting within the Net Worth Performance Chart. I need help in extracting this string alone which starts with PM. This string can be anywhere in the textbox. Help plz. I tried StringInStr and checked other commands as well. Might be I am missing something. Thanks. Regards, Sam
JohnOne Posted January 13, 2014 Posted January 13, 2014 Best and quickest way to get worthwhile help is to post what you have tried. Saves everyone time. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jdelaney Posted January 13, 2014 Posted January 13, 2014 (edited) You can use my signature...post your HTML source code, and I can narrow it down to grab exactly what you want...it's not case sensitive searching: $aMatches = BGe_IEGetDOMObjByXPathWithAttributes($oIE,"//textbox[contains(.,'your text')]") For $i = 0 To UBound($aMatches)-1 ConsoleWrite($aMatches[$i].innertext & @CRLF) Next Edited January 13, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
sammy1983 Posted January 13, 2014 Author Posted January 13, 2014 Best and quickest way to get worthwhile help is to post what you have tried. Saves everyone time. I couldn't find a way to do. I read through help files but couldn't get a command where I can search a partial string and get the entire word. As I said earlier, this particular string which starts with PM can be anywhere in the textbox. I have to search for it, get the entire word (PM123456) and save it in a cell of Excel sheet.
jdelaney Posted January 13, 2014 Posted January 13, 2014 (edited) You need to use the _IE functions to attach to the page, and then my function will work just fine. Also, that's not the source HTML, that's a screenshot of the textbox. #include <ie.au3> $oIE = _IEAttach("Your URL") ; Or _IECreate to create a new browser Edited January 13, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
sammy1983 Posted January 13, 2014 Author Posted January 13, 2014 You can use my signature...post your HTML source code, and I can narrow it down to grab exactly what you want...it's not case sensitive searching: $aMatches = BGe_IEGetDOMObjByXPathWithAttributes($oIE,"//textbox[contains(.,'your text')]") For $i = 0 To UBound($aMatches)-1 ConsoleWrite($aMatches[$i].innertext & @CRLF) Next Thanks for the help, jdelaney.. As this is my Client specific, I am not supposed to present source code on public Forum.. Sorry for this.. but I am desperately looking for a way to find and extract this String which will complete my project. Kindly help. Thanks.
jdelaney Posted January 13, 2014 Posted January 13, 2014 I just spoon fed you the answer, go try it! IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
sammy1983 Posted January 13, 2014 Author Posted January 13, 2014 I just spoon fed you the answer, go try it! I received error: "D:DesktopScriptsTest.au3" (55) : ==> Unknown function name.: $aMatches = BGe_IEGetDOMObjByXPathWithAttributes($oIE,"(.,'PM')]") $aMatches = ^ ERROR Here is the code: #include <IE.au3> #include <Date.au3> #include <String.au3> #Include <Array.au3> #include <Debug.au3> #include <Excel.au3> #NoTrayIcon Dim $aRecords Local $sDisplayname, $sDisp, $SumInfoId, $sCellValue Local $sFilePath1 = @ScriptDir & "WSR sheet.xlsx" ;This file should already exist Local $oExcel = _ExcelBookOpen($sFilePath1) ; Opens an existing excel File Local $file = FileOpen("Creds.txt", 0) $GMUsername = FileReadLine($file, 6) $GMPassword = FileReadLine($file, 7) $oIE = _IECreate("My URL") _IELinkClickByText($oIE, "Continue to this website (not recommended).") $oForm = _IEFormGetObjByName ($oIE, "loginForm") $oQuery1 = _IEFormElementGetObjByName ($oForm, "loginName") $oQuery2 = _IEFormElementGetObjByName ($oForm, "password") $oQuery3 = _IEFormElementGetObjByName ($oForm, "Submit") _IELoadWaitTimeout (50000) _IEFormElementSetValue ($oQuery1, $GMUsername) _IEFormElementSetValue ($oQuery2, $GMPassword) _IEAction ($oQuery3, "click") _IELoadWait ($oIE) _IELinkClickByText($oIE, "Close",0,1) _IELoadWait ($oIE) $sCellValue = _ExcelReadCell($oExcel, 4, 2) ; Reads the value of cell if $sCellValue = "" Then _IEQuit($oIE) Exit EndIf $oForm1 = _IEFormGetObjByName ($oIE, "generalSearchForm") $oQuery4 = _IEFormElementGetObjByName ($oForm1, "searchId") _IEFormElementSetValue ($oQuery4, $sCellValue) _IEAction($oQuery4, "focus") Send ("{Enter}") _IELoadWait($oIE) _IELinkClickByText($oIE, $sCellValue) _IELoadWait($oIE) $oIE = _IEAttach("My URL") $aMatches = BGe_IEGetDOMObjByXPathWithAttributes($oIE,"(.,'PM')]") For $i = 0 To UBound($aMatches)-1 ConsoleWrite($aMatches[$i].innertext & @CRLF) Next I think I am making some mistake in the code provided by you. Can u correct?
jdelaney Posted January 13, 2014 Posted January 13, 2014 you mangled the xpath I gave you. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
sammy1983 Posted January 13, 2014 Author Posted January 13, 2014 you mangled the xpath I gave you. Request you to kindly correct the code plz..
jdelaney Posted January 13, 2014 Posted January 13, 2014 You need to replace the _ieattach with your actual url...."Your URL" will not magically attach to browser. #include <ie.au3> $oIE = _IEAttach("Your URL") ; Or _IECreate to create a new browser $aMatches = BGe_IEGetDOMObjByXPathWithAttributes($oIE,"//textbox[contains(.,'PM')]") For $i = 0 To UBound($aMatches)-1 ConsoleWrite($aMatches[$i].innertext & @CRLF) Next IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
PhoenixXL Posted January 13, 2014 Posted January 13, 2014 I don't know anything about the excel sheets and objects, but if you can get the full string from the cell then this would be better ;the string returned is the one that is ; - enclosed in brackets( if many then the first one) ; - has only uppercase letter or digits Local $sFullString = "(PM1153125) Incorrect Amounts reflecting within the Net Worth Performance Chart." Local $sReqStr = StringRegExpReplace( $sFullString, ".*?\(([\060-\071\101-\132]*?)\).*", "\1") ConsoleWrite($sReqStr & @CRLF) Regards My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
BrewManNH Posted January 13, 2014 Posted January 13, 2014 Request you to kindly correct the code plz.. Did you look at the >link in his signature like he suggested? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Gianni Posted January 13, 2014 Posted January 13, 2014 (edited) if you already have the whole string and the required part is always within brackets why not use _StringBetween($s_String, "(",")") Edited January 13, 2014 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
sammy1983 Posted January 14, 2014 Author Posted January 14, 2014 Unfortunately, I was unable to retrieve that particular full string from Partial (PMxxxxxx) string using Autoit, however, I searched Excel tutorial and found a formula which can extract a particular string pattern. The formula is =MID(H4,FIND("PM",H4),9) Thanks to everyone for helping me. I really like the way Autoit Forum and its members are ready to assist anytime. Thanks again.
jdelaney Posted January 14, 2014 Posted January 14, 2014 (edited) Is that really all you wanted? $string = "(PM1153125) Incorrect Amounts" $newString = StringRegExpReplace($string,".*(PM\d+).*","$1") ConsoleWrite($newString & @CRLF) Or, more specifically to look within () $string = "(PM1153125) Incorrect Amounts" $newString = StringRegExpReplace($string,".*\((PM\d+)\).*","$1") ConsoleWrite($newString & @CRLF) Edited January 14, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
sammy1983 Posted January 14, 2014 Author Posted January 14, 2014 Is that really all you wanted? $string = "(PM1153125) Incorrect Amounts" $newString = StringRegExpReplace($string,".*(PM\d+).*","$1") ConsoleWrite($newString & @CRLF) Or, more specifically to look within () $string = "(PM1153125) Incorrect Amounts" $newString = StringRegExpReplace($string,".*\((PM\d+)\).*","$1") ConsoleWrite($newString & @CRLF) Thanks jdelaney. The numerical digits will not be always the same and its not necessary that this particular string will be in brackets. Sometime user will provide at the end, sometime in the beginning, sometime with brackets and sometimes without. However, the only pattern will remain same is that it will start with PM and proceed with 7 digits. Hope this clarifies and thanks for taking this extra mile effort me. Let me know if the above code could accomplish this. Thanks again.
jdelaney Posted January 14, 2014 Posted January 14, 2014 Change it to this then: $newString = StringRegExpReplace($string,".*(PM\d{7}).*","$1") IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
sammy1983 Posted January 14, 2014 Author Posted January 14, 2014 Change it to this then: $newString = StringRegExpReplace($string,".*(PM\d{7}).*","$1") Nope. Didn't work. I used the below one. Let me know if I did any mistake here. $oQuery7 = _IEFormElementGetObjByName ($oForm2, "summary.description") $Desc = _IEFormElementGetValue($oQuery7) ;Gets the content of Description textbox $newString = StringRegExpReplace($Desc,".*(PMd{7}).*","$1") _ExcelWriteCell($oExcel, $newString, 4, 20) ;Writes the value at 4th Row and 20th column in excel sheet
jdelaney Posted January 14, 2014 Posted January 14, 2014 Consolewrite the $Desc, and post it back. Consolewrite the $newString and post it back, also IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now