如何从Android服务中完整读取包含javascript的网站? [英] How to completely read a site that contains javascript from an android service?

查看:70
本文介绍了如何从Android服务中完整读取包含javascript的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从包含Java脚本的网站中读取一个节点.

I'm trying to read a node from a website that contains java script.

在VB .NET中,我只使用以下代码:

In VB .NET I just use the following code:

            Dim listSpan As IHTMLElementCollection = bodyel.getElementsByTagName("span")

            For Each spanItem As IHTMLElement In listSpan
                If spanItem.className & "" = "span_name" Then
                    If Not spanItem.innerText Is Nothing Then
                        str_result = spanItem.innerText.ToString
                        Console.WriteLine("Found it: " & str_result)
                    Else
                        str_result = "NO"
                        Console.WriteLine("Not Found")
                        Console.Beep(500, 500)
                    End If

                End If
            Next

但是我只是找不到一种方法来将该代码转换为可在Android服务中使用. (Java).

But I just can't find a way to convert this code to work in Android service. (Java).

我尝试了Jsoup,但Jsoup仅读取查看源代码"元素,而不是将javascript结果作为html.

I tried Jsoup but Jsoup is only reading the "view source code" elements and not the javascript results as html.

try {
    Document doc = Jsoup.connect(str_link).get();               
    Elements links = doc.select("span_name");

    for(Element link : links) {
    String result = link.text();  
    Log.d("TMA Service","result: " + result);
    list.add(title);

}

我的意思是. VB中的这段代码可以找到所有内容. (就像我右键单击使用Google chrome的元素并选择检查元素"一样.这将显示所有内容,我想知道如何使用Android获取此数据.

I mean. This code in VB can find everything. (just like if I right click in an element using google chrome and select "Inspect Element". This shows everything and I'd like to know how to get this data with Android.

有人可以举一个例子吗?

CAN SOME ONE GIVE ME AN EXAMPLE?

谢谢.

推荐答案

不幸的是,您无法使用Jsoup处理Javascript和动态内容.请在此处查看我的答案更多信息和Java库的一些示例,可能会对您有所帮助.

Unfortunately you can't handle Javascript and dynamic content with Jsoup. Please see my answer here for more information and some examples of Java libraries, that may help you here.

  • HtmlUnit - Getting started (section Getting started)
  • HtmlUnit: A Simple Example: Check Yahoo Email
  • How to use HtmlUnit in Java?
  • HtmlUnit: A Quick Introduction
  • HtmlUnit – A quick introduction
  • Getting started with HtmlUnit

这篇关于如何从Android服务中完整读取包含javascript的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆