Jump to content

How to collect a list of searching result?


oemript
 Share

Recommended Posts

52 minutes ago, Subz said:

Just remove the MsgBox, it's not required, it was only to show how to use _IEPropertyGet i.e.

I would look into _IEPropertyGet for study, I am very appreciated for all your help

Thanks, to everyone very much for suggestions (^v^)

 

Link to comment
Share on other sites

When I study on following coding, and I cannot find "ul" within inspector and view source from Google.

I would like to know on how to interpret following coding and where "ul" come from.

Local $oListBoxs = _IETagNameGetCollection($oIE, "ul")

_IETagNameGetCollection ( ByRef $oObject, $sTagName [, $iIndex = -1] )

TagName of collection to return (e.g. IMG, TR etc.)

Do you have any suggestions on how to handle this situation?
Thanks, to everyone very much for any suggestions (^v^)

 

Google8.png

Edited by oemript
Link to comment
Share on other sites

ul - stands for unordered list, this is dynamically created when you type in the search field, it doesn't exist if you view the page source by default because you need to type something first.

With regards to the code not working on another site, it won't, the code was written for www.google.com not world.taobao.com.  I've had a quick look and it's not as easy as Google Search, the following works but requires a 10 second delay, because the site pops up a banner which then strips the search field.  You will need to play around and try and get it to work as you like, the following should get you started:

#include <IE.au3>
Local $sFilePath = "D:\Sample.txt"
Local $sSendKey = "k"

Local $oIE = _IECreate("https://world.taobao.com/")
Sleep(6000)
Local $oInput = _IEGetObjByName($oIE, "q")
    _IEAction($oInput, "focus")
    ControlSend(_IEPropertyGet($oIE, "title"), "", "", $sSendKey)
    Sleep(2000)
    ControlSend(_IEPropertyGet($oIE, "title"), "", "", "{DOWN}")
    Sleep(2000)
Local $oSearchBox = _IEGetObjById($oIE, "oversea-searchbar")
Local $sSearch = ""
Local $oDivs = _IETagNameGetCollection($oSearchBox, "div")
For $oDiv In $oDivs
    If $oDiv.getAttribute("data-tpl") = "list" Then $sSearch &= StringStripWS($oDiv.Innertext, 7) & @CRLF
Next
MsgBox(0,'', $sSearch)

 

Link to comment
Share on other sites

7 hours ago, Subz said:
#include <IE.au3>
Local $sFilePath = "D:\Sample.txt"
Local $sSendKey = "k"

Local $oIE = _IECreate("https://world.taobao.com/")
Sleep(6000)
Local $oInput = _IEGetObjByName($oIE, "q")
    _IEAction($oInput, "focus")
    ControlSend(_IEPropertyGet($oIE, "title"), "", "", $sSendKey)
    Sleep(2000)
    ControlSend(_IEPropertyGet($oIE, "title"), "", "", "{DOWN}")
    Sleep(2000)
Local $oSearchBox = _IEGetObjById($oIE, "oversea-searchbar")
Local $sSearch = ""
Local $oDivs = _IETagNameGetCollection($oSearchBox, "div")
For $oDiv In $oDivs
    If $oDiv.getAttribute("data-tpl") = "list" Then $sSearch &= StringStripWS($oDiv.Innertext, 7) & @CRLF
Next
MsgBox(0,'', $sSearch)

 

Please see below images, which show the question 1, 2 and 3 on coding.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

Taobao3.png

Google9.png

Edited by oemript
Link to comment
Share on other sites

1. No, Title refers to the Title of the WebPage "淘宝网(淘寶網) 新西兰站 - Internet Explorer"
nb I don't know Chinese so just used the _IEPropertyGet to obtain the Web Page Title

2. id "oversea-searchbar" is the beginning of the SearchBox, I use this as the base item then request all divs below "oversea-searchbar".

3. I used role on Google because it gave me specific attribute to search for, unfortunately Googles ids are dynamic so they're not the same for you and I, however the "role" attribute is always the same, so I used this.

Link to comment
Share on other sites

Referring to the input field, I have tried different parameters to see on whether innertext can be output into text file or not.

The result is shown below PASS and FAIL. I don't understand on why innertext can ONLY be exported with coding $oListItem.getAttribute("role") = "option"

Do you have any suggestions on what wrong is with other parameters?
Thanks, to everyone very much for any suggestions (^v^)

Google10.png===================================================================================

For $oListBox In $oListBoxs
    If $oListBox.getAttribute("role") = "listbox" Then
        $oListItems = _IETagNameGetCollection($oListBox, "div")
        For $oListItem In $oListItems
            If $oListItem.getAttribute("role") = "option" Then
                If $oListItem.GetAttribute("role") = "option" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            EndIf

            ;If $oListItem.getAttribute("id") = "lst-ib" Then
            ;    If $oListItem.GetAttribute("id") = "lst-ib" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            ;EndIf
            ;If $oListItem.getAttribute("name") = "q" Then
            ;    If $oListItem.GetAttribute("name") = "q" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            ;EndIf
            ;If $oListItem.getAttribute("aria-autocomplete") = "list" Then
            ;    If $oListItem.GetAttribute("aria-autocomplete") = "list" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            ;EndIf
            ;If $oListItem.getAttribute("dir") = "ltr" Then
            ;    If $oListItem.GetAttribute("dir") = "ltr" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            ;EndIf
            ;If $oListItem.getAttribute("type") = "text" Then
            ;    If $oListItem.GetAttribute("type") = "text" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            ;EndIf
            ;If $oListItem.getAttribute("role") = "combobox" Then
            ;    If $oListItem.GetAttribute("role") = "combobox" Then $sSearch &= StringStripWS($oListItem.Innertext, 7) & @CRLF
            ;EndIf

        Next
    EndIf
Next

Edited by oemript
Link to comment
Share on other sites

You can't get InnerText from an Input, you can get the value, remember we used _IEGetObjByName($oiE, "q") which corresponds to the Search "<input ... name="q" ...>, to add data to the Input we use:

Local $oInput = _IEGetObjByName($oIE, "q")
    $oInput.Value = "k"

to get data from the input we would use:

Local $oInput = _IEGetObjByName($oIE, "q")
    MsgBox(32, "Input Value", $oInput.Value)

 

Link to comment
Share on other sites

Please see below images, which show the question 4 on coding for innerText.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Google10.png

Edited by oemript
Link to comment
Share on other sites

10 hours ago, Subz said:

to get data from the input we would use:

Local $oInput = _IEGetObjByName($oIE, "q")
    MsgBox(32, "Input Value", $oInput.Value)

 

From above coding, I would like to know on how to retrieve innertext in MsgBox without following coding condition.

Google11.png

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

Edited by oemript
Link to comment
Share on other sites

I don't think you understand the role attribute, the <input...> is playing the role of a "ComboBox" it's not actually a ComboBox, using CSS the suggested results are sent to an entirely different <div role="listbox">, below this are <div role="option">, now you could get InnerText from the "listbox" but you'll notice alot of rubbish at the end, which is why I chose to use the option role.

2018-03-04_10-36-28.jpg

Link to comment
Share on other sites

Please see following image for Q5 and Q6, there is another issues on how to handle attribute and search box as shown below.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Lazada1.png

Edited by oemript
Link to comment
Share on other sites

Most sites are going to have their own search functions, the code, id, names can be different for each website, you need to define the criteria, if you can do it be name or id then you can use_IEGetObjById or _IEGetObjByName, however if they don't you need to use something else like "role" attribute or some other attribute which is distinct.

For your example in the post above I would use the class attribute since it's unique, i.e. there is only one "search-box__popup" class on the page, you could also use "suggest-list" in place of "search-box__popup" as there is only one instance of that class.

#include <IE.au3>
Local $sSendKey = "k"
Local $oIE = _IECreate("http://www.lazada.com.my")
Local $oInput = _IEGetObjByName($oIE, "q")
    _IEAction($oInput, "focus")
    ControlSend(_IEPropertyGet($oIE, "title"), "", "", $sSendKey)
    Sleep(2000)
    ControlSend(_IEPropertyGet($oIE, "title"), "", "", "{DOWN}")
    Sleep(2000)
    Local $oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv In $oDivs
    If StringInStr($oDiv.ClassName, "search-box__popup") Then MsgBox(32, "Search Box Popup", StringStripWS($oDiv.InnerText, 7))
Next

 

Link to comment
Share on other sites

Please see following image sample.txt, if there is only one instance of that class, then how to include break? so each innertext is displayed  on each line on sample.txt file.

Furthermore, since class="suggest-common--2KmE" occur on each instance, I have tried to use "suggest-common" instead of "search-box__popup", but it fails to display innerText.

Lazada3.png

I am very appreciated for all your help, do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Lazada2.png

 

 

Edited by oemript
Link to comment
Share on other sites

2 hours ago, Subz said:

You do realise that your getting the class name from <a> not <div> so you have to modify

Local $oDivs = _IETagNameGetCollection($oIE, "div")

To

Local $oDivs = _IETagNameGetCollection($oIE, "a")

Based on a few sample, I understand on how it works and solve the handling issues.

I am very appreciated for all your help
Thanks, to everyone very much for any suggestions (^v^)

 

 

 

Link to comment
Share on other sites

Please see following image,  I would like to know on what attribute to define $oInput for Class Object as shown below.

Shop1.png

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

Edited by oemript
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...