MaoMao Posted December 12, 2011 Share Posted December 12, 2011 Trying to perform multiple entry search to collect data and then extract result.Please help for Autoit Google Advance Search : How to get multiple result in th site .http://www.google.com/advanced_search?hl=en Examples program need help.Try to run the following code. Need advice for the following:1. Enter the search action and submit the entry. Submit function and read text not working.2. Display the search result message. Can not get it dsiplay in the msg box. Javascript in your browser. ...#include <IE.au3> #include <String.au3> $oIE = _IECreate("http://www.google.com/advanced_search?hl=en") $oForm = _IEFormGetCollection ($oIE, 0) $oQuery = _IEFormElementGetCollection ($oForm, 1) _IEFormElementSetValue ($oQuery, "Chrome") $oQuery = _IEFormElementGetCollection ($oForm, 2) _IEFormElementSetValue ($oQuery, "Windows") $oQuery = _IEFormElementGetCollection ($oForm, 3) _IEFormElementSetValue ($oQuery, "download") $netinfo = _IEFormSubmit ($oForm) ;(?????Test Line Error code) $sText = _IEBodyReadText ($netinfo) ;(??????Test Line Error code) ;~ MsgBox(0,'',$sText) MsgBox(0,'msg',$sText) ;(Test Line can not display text) $data1 = _StringBetween($sText, 'id=resultStats>About', '<nobr>') MsgBox(0,'Msg Result',$data1) ;(Test Line try To display text) $ss1 = StringSplit($sText, 'Search Results',1) $ss2 = StringSplit($ss1[1],@CRLF,1) $data2 = StringReplace(StringReplace($ss2[1],' ...',@CRLF),'JavaScript in your browser. [b]...[/b]')&@CRLF&$ss2[3] ;MsgBox(0,$data1[0]&')',$data2) MsgBox(0,'Msg2',$data2)Try to Retrieve Result in Msg box, not working yet need advice:1)About 408,000,000 results (0.14 seconds) 2)Search Results Google Chrome for Windows - Terms and Conditions Agreement https://www.google.com/chrome/eula.html - Cached You +1'd this publicly. Undo Google Chrome. You need a Javascript-capable browser to download this software. Click here for instructions on how to enable Javascript in your browser. ... Link to comment Share on other sites More sharing options...
FredAI Posted December 12, 2011 Share Posted December 12, 2011 Well, to retrieve the result count you may use: ;Get the html code of the results page Local $Keyword = 'AutoIt' Local $Url = 'http://www.google.com/search?q=' & $Keyword Local $Html = BinaryToString(InetRead($Url)) ;Get only the body code $Html = StringMid($Html,StringInStr($Html,'<body')) ;Remove the javascripts $Html = StringRegExpReplace($Html,'(?s)(?i)<script.+?script>','') ;Retrieve the visible text Local $Text = StringRegExpReplace($Html,'(?s)<.+?>','') Local $aTest = Stringregexp($Text,'(?s)(?i)Searchresults.+?'&$Keyword,2),$nResult If Not @error Then $nResult = $aTest[0] MsgBox(0,'',$nResult) Then, you just have to keep using string regexp to get the results. What do you want to retrieve? the links? My UDFs: SetAcl permissions | System restore Examples: File version info editor | GetIp() improved Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico Link to comment Share on other sites More sharing options...
MaoMao Posted December 13, 2011 Author Share Posted December 13, 2011 Thanks. The text and no. of result will do. Still not able to submit miltiple entry then return the web site search Text. Need advice for the following: 1. Enter the search action and submit the entry. Submit function and read text not working. #include <IE.au3> #include <String.au3> Local $Keyword = 'Chrome' Local $Keyword1 = 'Windows' Local $Keyword2 = 'download' $oIE = _IECreate("http://www.google.com/advanced_search?hl=en") $oForm = _IEFormGetCollection ($oIE, 0) $oQuery = _IEFormElementGetCollection ($oForm, 1) _IEFormElementSetValue ($oQuery, $Keyword) $oQuery = _IEFormElementGetCollection ($oForm, 2) _IEFormElementSetValue ($oQuery, $Keyword1) $oQuery = _IEFormElementGetCollection ($oForm, 3) _IEFormElementSetValue ($oQuery, $Keyword2) $netinfo = _IEFormSubmit ($oForm, 1) ;(?Test Line not able to get the resilt ) $nText = _IEBodyReadText ($netinfo) ;(??????Test Line not able to read text) MsgBox(0,'Text',$nText) $sText = _IEBodyReadText ($oForm) ;(??????Test Line not able to read text) MsgBox(0,'msg', $sText ) ;(Test Line can not display text) ;Get the html code of the results page $Url = $netinfo Local $Html = BinaryToString(InetRead($Url)) ;(??????Test Line not able to read text) ;Get only the body code $Html = StringMid($Html,StringInStr($Html,'<body')) ;Remove the javascripts $Html = StringRegExpReplace($Html,'(?s)(?i)<script.+?script>','') ;Retrieve the visible text Local $Text = StringRegExpReplace($Html,'(?s)<.+?>','') MsgBox(0,'VISIBLE TEXT',$Text) Local $aTest = Stringregexp($Text,'(?s)(?i)Searchresults.+?'&$Keyword,2),$nResult If Not @error Then $nResult = $aTest[0] MsgBox(0,'RESULT',$nResult) Link to comment Share on other sites More sharing options...
FredAI Posted December 13, 2011 Share Posted December 13, 2011 Why make it simple when you can make it complicated? Why do you want to use the IE functions. All you need is to read the page with the results. If you do your search manually, you'll see that the url of the results page is: http://www.google.com/search?q=Chrome+%22Windows%22+download&hl=en&num=10&lr=&ft=i&cr=&safe=images So, all you have to do is read and parse this url: ;Get the html code of the results page Local $Keyword = 'Chrome' Local $Keyword1 = 'Windows' Local $Keyword2 = 'download' Local $Url = 'http://www.google.com/search?q='&$Keyword&'+%22'&$Keyword1&'%22+'&$Keyword2&'&hl=en&num=10&lr=&ft=i&cr=&safe=images' Local $Html = BinaryToString(InetRead($Url)) ;Get only the body code $Html = StringMid($Html,StringInStr($Html,'<body')) ;Remove the javascripts $Html = StringRegExpReplace($Html,'(?s)(?i)<script.+?script>','') ;Retrieve the visible text Local $Text = StringRegExpReplace($Html,'(?s)<.+?>','') ;Retrieve the result count Local $aTest = Stringregexp($Text,'(?s)(?i)Searchresults.+?'&$Keyword2,2),$nResult If Not @error Then $nResult = StringReplace($aTest[0],'"','+') $nResult = StringReplace($nResult,'Searchresults','Search results:') EndIf ;Display the result count MsgBox(0,'','Result count:'&@CRLF&$nResult) ;Display the visible text MsgBox(0,'','Page text:'&@CRLF&$Text) Hop it helps. My UDFs: SetAcl permissions | System restore Examples: File version info editor | GetIp() improved Programs: UVK - Ultra virus killer | ExeFixer | Recent file seeker | SHIcon | Quick_Any2Ico Link to comment Share on other sites More sharing options...
MaoMao Posted December 13, 2011 Author Share Posted December 13, 2011 (edited) Thanks for the help.The reason use IE is to create a generic program to later apply to other search engines.i.e. http://sourceforge.net/ http://www.ebay.com/sch/ebayadvsearch/?_skipfnorm=1&rt=nc http://www.hotels.com/ etc....The URL function does the job nice and simple for google in one line :http://www.google.com/search?q=Chrome+%2...ad&hl=en&num=10&lr=&ft=i&cr=However, not all the search engine may use the URL function in one line.Good if any advice to make multiple entries for search engine step by step then retrieve the search result. Edited December 13, 2011 by MaoMao Link to comment Share on other sites More sharing options...
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