0
我是VBA的新手,如果此問題顯示格式不正確,請致歉,因爲我不知道如何在此處做得更好。無法使用VBA從班級名稱中刪除表格
目前,我試圖從網站備案,但沒有成功下載數據,它自帶了一個「運行時錯誤438,我也嘗試使用不同的metheods像
getElementsByClassName方法看爲「M_box」,「M_content」和「pub_table」,
getElementsByID尋找「datatb」
但沒有成功。我也試過以下,但也未能
get.ElementByClassName( 「M_content」)(0).getElementsByID( 「datatb」)(1) get.ElementByClassName( 「M_content」)(0)。的getElementsByTagName( 「表」)(1)
Sub GetAsianOdds()
Dim IE As Object
Dim r As Integer, c As Integer, t As Integer, x As Integer
Dim ElementHtml As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate ("http://odds.500.com/fenxi/yazhi-567405")
While IE.readyState <> 4
DoEvents
Wend
MsgBox "IE is ready"
Set ElementHtml = IE.Document.getElementsByClassName("pub_table") <--Run Time Error happens here
For t = 0 To (ElementHtml.Length - 1)
For r = 0 To (ElementHtml(t).Rows.Length - 1)
For c = 0 To (ElementHtml(t).Rows(r).Cells.Length - 1)
Set ThisWorkbook.Worksheets("Test").Cells(r + 1, c + 1).Value = ElementHtml(t).Rows(r).Cells(c).innerText
Next c
Next r
Next t
End With
IE.Quit
Set IE = Nothing
End Sub
並且在下面有關網站的部分的HTML代碼
<div class="mar_b yz_contrast">
<div class="M_box">
<div class="M_title"><h2>...</h2></div>
<div class="M_content">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="pub_table" id="datatb">
<tr>
<th class="th_one"><label>...</label></th>
<th>...</th>
<th width="55">...</th>
<th width="120">...</th>
<th width="55">...</th>
<th>...</th>
<th width="55">...</th>
<th width="90">...</th>
<th width="55">...</th>
<th>...</th>
<th>...</th>
</tr>
任何人都可以引導我如何解決這個問題呢?
非常感謝!