我正在尝试抓取一个包含投注赔率数据的网站。
页面的编写方式,它在标签标记中列出了市场名称,该标签不是选择的父项,而是页面的分隔符。
使用JSoup,我可以提取所有想要的选择数据,但是我不知道如何弄清楚'label'的先前值是用于选择的。因此,实际上,我在页面上拥有所有选择和价格,但我无法确定“巴西4美元”是否与世界杯市场,得分最高的球队或任何其他市场有关。
我用来获取市场和选择的代码是:
Elements marketNames = doc.getElementsByTag("label");
Elements runnerNames = doc.getElementsByClass("selection");
基本上现在我有一个类似“巴西-$ 4.0”的选择。我还想知道以前的标签是什么,所以我可以将其称为“冠军-巴西-$ 4.0”
如果需要上一个标签,则可以遍历div标签,以便了解标签的顺序。
Elements divs = doc.select("div.sports_FfCell"); //gets the div part that has the information you want.
for (Element div : divs) {
if (div.toString().contains("market")) //there is a market tag for the table labels (sports_FfCell market).
System.out.print(div.text() + " - "); //no new line after the winner text.
else
System.out.println(div.text().replace("MULTI", "- ")); //it gets the MULTI part too, so i replace it.
}
输出:
Place Win World Cup 2014
Winner - Brazil - 3.75
Argentina - 5.00
Germany - 6.50
Spain - 7.00
Belgium - 21.00
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句