第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從上一個(gè)網(wǎng)頁(yè)而不是重定向網(wǎng)頁(yè) VBA 填充的 HTML 元素集合

從上一個(gè)網(wǎng)頁(yè)而不是重定向網(wǎng)頁(yè) VBA 填充的 HTML 元素集合

呼喚遠(yuǎn)方 2023-10-17 17:02:23
下面的代碼導(dǎo)航到網(wǎng)頁(yè),用查詢填充搜索框,然后提交到結(jié)果頁(yè)面。但是,腳本中的最終元素集合 tdtags(在重定向后定義)是從原始搜索頁(yè)面而不是結(jié)果頁(yè)面提取數(shù)據(jù)。我目前在腳本中有 while ie.busy 循環(huán)和定時(shí)延遲,但兩者都不起作用。我也嘗試過(guò)等待,直到僅出現(xiàn)在結(jié)果頁(yè)面中的元素在 html 中可用,但這也不起作用。Dim twb As WorkbookDim ie As ObjectSet twb = ThisWorkbooktwb.ActivateSet ie = CreateObject("internetexplorer.application")'church = Sheets("Control").Range("A2").Value'minister = Sheets("Control").Range("A4").Valuelocation = "London" 'Sheets("Control").Range("A6").Value'denomination = Sheets("Control").Range("A8").ValueWith ie.navigate "http://www.ukchurch.org/index.php".Visible = TrueDo While .Busy Or .ReadyState <> 4DoEventsLoopEnd WithApplication.Wait (Now + TimeValue("00:00:02"))Set intags = ie.document.getelementsbytagname("input")For Each intag In intagsIf intag.getattribute("name") = "name" ThenIf church <> "" Thenintag.Value = churchEnd IfElseIf intag.getattribute("name") = "minister" ThenIf minister <> "" Thenintag.Value = ministerEnd IfElseIf intag.getattribute("name") = "location" ThenIf location <> "" Thenintag.Value = locationEnd IfElseEnd IfNext intagSet dropopt = ie.document.getelementsbytagname("select")For Each dropo In dropoptIf dropo.classname = "DenominationDropDown" ThenSet opttags = dropo.getelementsbytagname("option")For Each opt In opttagsIf opt.innertext = denomination Thenopt.Selected = TrueEnd IfNext optEnd IfNext dropoOn Error Resume NextFor Each intag In intagsIf intag.getattribute("src") = "images/ukchurch/button-go.jpg" Thenintag.ClickDo While ie.Busy Or ie.ReadyState <> 4DoEventsLoopApplication.Wait (Now + TimeValue("00:00:03"))Exit ForEnd IfNext intagApplication.Wait (Now + TimeValue("00:00:03"))Set tdtags = ie.document.getelementsbytagname("td")For Each td In tdtagsIf td.classname = "pText" ThenDebug.Print td.innertextDebug.Print ie.locationURLpagecount = Right(td.innertext, InStr(td.innertext, ":"))End IfNext tdDebug.Print pagecountEnd Sub任何診斷將不勝感激。
查看完整描述

1 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

自動(dòng)化 IE 很痛苦,所以要避免它。


以下函數(shù)直接請(qǐng)求結(jié)果頁(yè)面。


Public Function GetSearchResult(Optional ByVal ResultPage As Integer = 0, Optional ByVal ChurchName As String = "", Optional ByVal Minister As String = "", Optional ByVal ChurchLocation As String = "", Optional ByVal Denomination As String = "") As Object

Dim Request As Object: Set Request = CreateObject("MSXML2.serverXMLHTTP")

Dim Result As Object: Set Result = CreateObject("htmlfile")


Request.Open "POST", "http://www.ukchurch.org/searchresults1.php", False

Request.setRequestHeader "content-type", "application/x-www-form-urlencoded"

Request.send IIf(ResultPage = 0, "", "page=" & ResultPage & "&") & "name=" & ChurchName & "&minister=" & Minister & "&location=" & ChurchLocation & "&denomination=" & Denomination


Result.body.innerHTML = Request.responseText


Set GetSearchResult = Result

End Function

打印包含搜索結(jié)果的表中tdwith classname的內(nèi)容的示例pText


Sub Main()

Dim Document As Object

Set Document = GetSearchResult(ChurchLocation:="London")

Dim ResultRows as Object

Dim ResultRow As Object

Set ResultRows = Document.getElementsByTagName("table")(8).getElementsByTagName("td")

For Each ResultRow in ResultRows

    If ResultRow.Classname = "pText" Then

        Debug.print ResultRow.innerText

    End If

Next

End Sub

更新 您需要向 VBA 項(xiàng)目添加一些引用才能使以下代碼正常工作。


在 VBA 編輯器中,轉(zhuǎn)到“工具”菜單,單擊“引用”,然后在打開(kāi)的對(duì)話框中在以下兩項(xiàng)旁邊添加復(fù)選標(biāo)記:Microsoft XML, v6.0和Microsoft HTML Object Library(


Public Function GetChurchDetails(ByVal ChurchID As String) As MSHTML.HTMLDocument

Dim Request As New MSXML2.ServerXMLHTTP60

Dim Result As New MSHTML.HTMLDocument


Request.Open "GET", "http://www.ukchurch.org/churchdetails.php?churchid=" & ChurchID, False

Request.send


Result.body.innerHTML = Request.responseText

Set GetChurchDetails = Result

End Function


Sub Main2()

Dim Document As MSHTML.HTMLDocument

Dim Church As MSHTML.HTMLDocument

Set Document = GetSearchResult(ChurchLocation:="London")

Dim ResultRows As MSHTML.IHTMLElementCollection

Dim ResultRow As MSHTML.IHTMLElement

Dim ChurchID As String

'Set ResultRows = Document.getElementsByTagName("table")(8).getElementsByTagName("td")

' all result links on searchresults1.php have a classname of resultslink which makes getting them much easier

Set ResultRows = Document.getElementsByClassName("resultslink")

For Each ResultRow In ResultRows

    ChurchID = ResultRow.getAttribute("href")

    ChurchID = Mid(ChurchID, InStr(1, ChurchID, "=") + 1)

    Set Church = GetChurchDetails(ChurchID)

    ' code to read data from the page using Church as the Document

    ' eg: Church.getElemenetsByTagName("td").....

Next

End Sub

您只需要在提交數(shù)據(jù)時(shí)使用“post”模式,其他一切都可以使用“get”模式


查看完整回答
反對(duì) 回復(fù) 2023-10-17
  • 1 回答
  • 0 關(guān)注
  • 200 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)