我无法在IE网站的表格中点击最佳投注搜索结果

时间:2017-10-12 19:15:54

标签: excel-vba vba excel

我相对较新,很抱歉,如果这是基本的。这里什么都没有帮助我。我试图自动化一个功能,但无法克服这个问题。当我在网站中搜索某些内容时,它会返回一个表格并单击任何搜索选项非常简单,因为功能菜单ID就像x1一样简单。然而,图表格式化为顶部的“最佳下注”行,这总是我希望它选择的选项,并且此ID根据我搜索的变量而变化,因此我无法根据ID选择它,因为它会不断变化。而不是打开功能菜单我只想让它点击最佳下注行中的按钮。任何的意见都将会有帮助。对于上下文GetElementByID(“x1017538”)。单击是问题发生的位置。

Sub Mirror_Mover()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

Dim MMD As Workbook
Set MMD = ThisWorkbook

Dim Mirror_Mover As Worksheet
Set Mirror_Mover = Sheets("Mirror Mover")

Dim inputRng As Range
Dim lastRow As Integer
Set inputRng = Mirror_Mover.Range("A:D")
lastRow = Application.WorksheetFunction.Max(Range("A" & Rows.Count).End(xlUp).Row, Range("D" & Rows.Count).End(xlUp).Row)

Dim Box As Range
Dim LLT As Range
Dim PRO As Range
Dim FLD As Range

Dim i As Integer
For i = 1 To lastRow
If inputRng(i, 1).Value <> vbNullString Then
Set Box = inputRng(i, 1)
Set LLT = inputRng(i, 2)
Set PRO = inputRng(i, 3)
Set FLD = inputRng(i, 4)

'Open Internet Explorer and Navigate main page
IE.Visible = True
IE.Navigate "website"
Application.Wait (Now + #12:00:05 AM#)

'Locate the item to which folder will be added
IE.Document.GetElementByID("fulltextwhere1").Value = PRO
IE.Document.GetElementByID("fulltextsubmitButton").Click
Application.Wait (Now + #12:00:05 AM#)

'Open the top search result
IE.Document.GetElementByID("x1017538").Click
Do While IE.Busy: DoEvents: Loop
Do While IE.ReadyState <> 4: DoEvents: Loop
IE.Document.GetElementByID("funcMenu101753816.1").Click
Do While IE.Busy: DoEvents: Loop
Do While IE.ReadyState <> 4: DoEvents: Loop

<TR CLASS="bestBetRow1"  TITLE="Best Bet 1">

<TD ALIGN="CENTER" WIDTH="1%" VALIGN="TOP" STYLE="padding: 3px" NOWRAP>&nbsp;<IMG HEIGHT="9" ALT="" HSPACE="3" SRC="/img/spacer.gif" WIDTH="11" BORDER="0"></TD>
<TD NOWRAP ALIGN="CENTER" TITLE="Score">

&nbsp;
</TD>

<TD NOWRAP ALIGN="CENTER" TITLE="MIME Type">







<A HREF="cs.exe?func=ll&amp;objId=1017538&amp;objAction=browse"><img class="objectIcon" src="/img/webdoc/folder.gif" alt="Folder" title="Folder"></A>
</TD>

<TD NOWRAP  TITLE="TEXT">


<SPAN CLASS="important"><A HREF="cs.exe?func=ll&amp;objId=1017538&amp;objAction=browse">TEXT</A></SPAN>
<A HREF="#" ONCLICK="setSectionName('');showFunctionMenu2('nextURL=%2Fotcs%2Fcs%2Eexe%3Ffunc%3Dsrch%2ESearchCache%26cacheId%3D697991735', '1017538', event, '', '' );setSectionName('');return false"><IMG SRC="/img/actions.png" ID="x1017538" BORDER="0" ALT="Functions" TITLE="Functions" ONMOUSEOVER="this.src='/img/actions_hover.png'" ONMOUSEOUT="this.src='/img/actions.png'"></A>
<DIV ID="z1017538" CLASS="functionMenuDiv"  ></DIV>

&nbsp;<SPAN CLASS="bestBetLabel">-&nbsp;Nickname&nbsp;(TEXT)</SPAN>

</TD>

<TD NOWRAP ALIGN="CENTER" TITLE="Date: 09/28/2017">
09/28/2017

</TD>

<TD NOWRAP ALIGN="CENTER" TITLE="Size: 21 Items">

21 Items
</TD>

<TD NOWRAP  TITLE="Location: Enterprise:TEXT">

<DIV class="search-breadcrumb-trail">
<A HREF="cs.exe?func=ll&objId=2000&objAction=browse" CLASS="locationDisplayTrailNonterminalElement" TITLE="Go to Enterprise">Enterprise</A>
<SPAN CLASS="separatorImage">&nbsp;</SPAN>
<A HREF="cs.exe?func=ll&objId=611814&objAction=browse" CLASS="locationDisplayTrailNonterminalElement" TITLE="Go to Properties">Properties</A>
<SPAN CLASS="separatorImage">&nbsp;</SPAN>
<A HREF="cs.exe?func=ll&objId=611815&objAction=browse" CLASS="locationDisplayTrailNonterminalElement" TITLE="Go to TEXT">TEXT</A>
<SPAN CLASS="separatorImage">&nbsp;</SPAN>
<A HREF="cs.exe?func=ll&objId=611882&objAction=browse" CLASS="locationDisplayTrailNonterminalElement" TITLE="Go to TEXT">TEXT</A>
<SPAN CLASS="separatorImage">&nbsp;</SPAN>
<A HREF="cs.exe?func=ll&objId=611889&objAction=browse" CLASS="locationDisplayTrailTerminalElement" TITLE="Go to TEXT">TEXT</A>
</DIV>


</TD>

<TD NOWRAP ALIGN="CENTER" TITLE="OTCreatedBy">



<A HREF="#" onClick="doUserDialog( '608559' )">Properties Folder Administrator (property_administrator)</A>
<SCRIPT LANGUAGE="JavaScript">

function doUserDialog( userID )
{
var		w = window.open('/cs.exe?func=user.userdialog&userID=' + userID,'UserDialog','width=600,height=440,resizable=yes,scrollbars=yes,menubar=no');

if ( w.focus )
{
w.focus();
}
}

</SCRIPT>

</TD>

</TR>

1 个答案:

答案 0 :(得分:0)

2017-10-27修订以考虑以下评论。 修订2017-11-02以修复编码错误

您可以尝试以下内容。

请注意,此代码尚未编译或调试。

'// Find the best bet row <TR> element
Dim bestBetRow As Object
Set bestBetRow = IE.Document.getElementsByClassName("bestBetRow1")(0)

'// Use the findRequiredLink function to find the element to be clicked
Dim link As Object
Set link = findRequiredLink(bestBetRow)

'// Check that the element is found and click it if so
If Not link Is Nothing Then
    link.Click
End If

:
:

Function findRequiredLink(parent As Object) As Object
'// This function uses recursion from a root node
'// to find a specific IMG node that meets the required
'// criteria, i.e. has the TITLE attribute set to "Functions"

    Dim child As Object
    Dim ix as integer

    '// check each child node in turn
    For ix = 0 to parent.ChildNodes.Length-1

        '// get the child node
        Set child = parent.ChildNodes.Item(ix)

        '// does it meet the required criteria?
        if child.tagName = "IMG" and _
            child.getAttribute("TITLE")="Functions" then
            set findRequiredLink = child
            exit function
        end if

        '// Recursively check the children of the child
        Set child = findRequiredLink(child)

        '// Check if the anchor was found amongst the children
        if Not child Is Nothing then
            Set findRequiredLink = child
            exit Function
        End If

    Next ix

    '// No matching node was found - return nothing
    Set findRequiredLink = Nothing
end function