简体   繁体   English

Excel VBA-网站抓取

[英]Excel VBA - Website Scrape

I have spent hours searching for the answer to this, but I can't find one. 我已经花了数小时来寻找答案,但是找不到。

I am trying to extract data from this website 我正在尝试从该网站提取数据

I have managed to get most of what I need, but I'm finding it difficult to target a specific data point. 我已经设法满足了我的大部分需求,但是我发现很难针对特定的数据点。

The closest piece of code I've used is: 我使用过的最接近的代码是:

 hDoc.getElementsByClassName("table-matches__odds")(0).outerHTML

which outputs the below which isn't what I want 输出以下不是我想要的

class=table-matches__odds data-odd-max="5.50" data-odd="5.19" class = table-matches__odds data-odd-max =“ 5.50” data-odd =“ 5.19”

I only want the data-odd= part of this, so the 5.19 but can't figure out how to target it. 我只希望其中的data-odd=部分,所以5.19但无法弄清楚如何定位它。 I could use instr to pull the data I need out of that, but is there a more specific way? 我可以使用instr从中提取所需的数据,但是还有更具体的方法吗?

The html looks like this for the section i'm trying to extract: 对于我要提取的部分,html看起来像这样:

<TH class=h-text-left colSpan=8><A href="about:/soccer/england/premier-league/">Premier League 2016/2017</A></TH></TR>
<TR data-dt="5,2,2017,17,00">
<TD>Leicester</TD>
<TD><STRONG>Manchester United</STRONG></TD>
<TD class=h-text-center>0:3</TD>
<TD class=table-matches__odds data-odd-max="5.50" data-odd="5.19"></TD>
<TD class=table-matches__odds data-odd-max="4.00" data-odd="3.79"></TD>
<TD class="table-matches__odds colored"><SPAN><SPAN><SPAN data-odd-max="1.80" data-odd="1.72"></SPAN></SPAN></SPAN></TD>
<TD><A href="about:/soccer/england/premier-league/leicester-manchester-united/G0fXjMCK/">details</A></TD>
<TD class=h-text-right>05.02.2017</TD></TR>
<TR data-dt="24,9,2016,13,30">
<TD><STRONG>Manchester United</STRONG></TD>
<TD>Leicester</TD>
<TD class=h-text-center>4:1</TD>
<TD class="table-matches__odds colored"><SPAN><SPAN><SPAN data-odd-max="1.73" data-odd="1.69"></SPAN></SPAN></SPAN></TD>
<TD class=table-matches__odds data-odd-max="4.05" data-odd="3.85"></TD>
<TD class=table-matches__odds data-odd-max="5.75" data-odd="5.34"></TD>
<TD><A href="about:/soccer/england/premier-league/manchester-united-leicester/dOBfynxf/">details</A></TD>
<TD class=h-text-right>24.09.2016</TD></TR>

Any help would be much appreciated 任何帮助将非常感激

Thanks 谢谢

You could declare it as a string 您可以将其声明为字符串

Dim sResult as String

and then derive the 5.19 value with this: 然后使用以下方法导出5.19值:

sResult = Mid(sResult, InStr(sResult, "data-odd=""") + Len("data-odd="""), 4) - this assumes that it's always 2 decimal places and it's also stored as a string rather then a double sResult = Mid(sResult, InStr(sResult, "data-odd=""") + Len("data-odd="""), 4) -假定它始终是2个小数位,并且也存储为字符串而不是一个双

Out of interest, are you trying to build an arbing screener? 出于兴趣,您是否正在尝试构建套叠筛选器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM