简体   繁体   English

Java从网页获取JavaScript内容

[英]Java get javascript content from webpage

I'm looking to get data from Betfair live stats of football. 我希望从必发的足球比赛实时数据中获取数据。 I have found a link to the stats part of the webpage, which is here: 我找到了指向该网页的统计信息部分的链接,位于此处:

https://wab-visualisation.performgroup.com/csb/index.html?wbuserId=0&token=f6eb1c7fff3ad3ca5153b159ac4b8b69fcb117ec7578893e5c9f9f6a608503fe4e64ebad85c7e4faa8ddea4e8ce70e99ce88551b77b8fe02616b56bf89af950ad89984a1cfcc8eb589dd1679b8204e8e0983fdff5c7599d00cabd805c0bd18aaf29485b0c122413c89ad5f7e70684e5f1609dea97f05286919f137baab64d36b&width=374&height=214&cssdiff=https%3a%2f%2fassets.cdnbf.net%2fstatic%2fdatavis%2fbf-css%2fbetfair1.css&flash=y&streamonly=true&partnerId=7&statsswitch=false&lang=en&defaultview=stats&version=1.15 https://wab-visualisation.performgroup.com/csb/index.html?wbuserId=0&token=f6eb1c7fff3ad3ca5153b159ac4b8b69fcb117ec7578893e5c9f9f6a608503fe4e64ebad85c7e4faa8ddea4e8ce70e99ce88551b77b8fe02616b56bf89af950ad89984a1cfcc8eb589dd1679b8204e8e0983fdff5c7599d00cabd805c0bd18aaf29485b0c122413c89ad5f7e70684e5f1609dea97f05286919f137baab64d36b&width=374&height=214&cssdiff=https%3a%2f%2fassets.cdnbf.net%2fstatic%2fdatavis%2fbf-css%2fbetfair1。 css&flash = y&streamonly = true&partnerId = 7&statsswitch = false&lang = en&defaultview = stats&version = 1.15

(The page changes regularly, so please check https://www.betfair.com/sport/inplay and select any match, then get the source of the "match panel" on the left) (页面会定期更改,因此请检查https://www.betfair.com/sport/inplay并选择任何匹配项,然后在左侧获取“匹配项面板”的来源)

However, when I try to scrape this with JSoup, it doesn't seem to return anything. 但是,当我尝试使用JSoup进行刮擦时,它似乎未返回任何内容。

    Document doc = Jsoup.connect("https://wab-visualisation.performgroup.com/csb/index.html?wbuserId=0&token=f6eb1c7fff3ad3ca5153b159ac4b8b69fcb117ec7578893e5c9f9f6a608503fe4e64ebad85c7e4faa8ddea4e8ce70e99ce88551b77b8fe02616b56bf89af950ad89984a1cfcc8eb589dd1679b8204e8e0983fdff5c7599d00cabd805c0bd18aaf29485b0c122413c89ad5f7e70684e5f1609dea97f05286919f137baab64d36b&width=374&height=214&cssdiff=https%3a%2f%2fassets.cdnbf.net%2fstatic%2fdatavis%2fbf-css%2fbetfair1.css&flash=y&streamonly=true&partnerId=7&statsswitch=false&lang=en&defaultview=stats&version=1.15").get();

    doc.select("#in-game-stats > div:nth-child(1) > div.si-home-value").text();

Am I doing something wrong? 难道我做错了什么? Is there a way around this? 有没有解决的办法?

Thanks 谢谢

The response is in plain text, there is no DOM that you can query. 响应采用纯文本格式,没有可以查询的DOM。 You might want to look at Selenium with PhantomJS driver to emulate user-agent actions. 您可能想看看带有PhantomJS驱动程序的Selenium来模拟用户代理动作。 Whether it's legal to scape data from that site or not, is another question. 另一个问题是从该站点获取数据是否合法。

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

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