Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

javascript - 如何在Eclipse中使用Javascript从没有明显类ID的表中解析数据(How to Parse Data from a Table with No Obvious Class IDs using Javascript in Eclipse)

I am trying to parse data from sites with a format similar to this one to retrieve surface observation for weather stations using Jscript ( https://mesowest.utah.edu/cgi-bin/droman/meso_base_dyn.cgi?stn=KSLC&unit=0&timetype=GMT )

(我正在尝试从格式类似于此格式的站点解析数据以使用Jscript检索气象站的地面观测( https://mesowest.utah.edu/cgi-bin/droman/meso_base_dyn.cgi?stn=KSLC&unit=0&timetype = GMT ))

I have developed a script that allows me to take user input of any site and parse the title and a brief description, but I don't appear to be able to use the element class to pull data from this table.

(我已经开发了一个脚本,该脚本可以让我接受任何站点的用户输入并解析标题和简短描述,但是我似乎无法使用element类从该表中提取数据。)

I am not all that familiar with html, so any guidance here would be especially helpful!

(我不太熟悉html,因此这里的任何指导特别有用!)

Here is my code so far:

(到目前为止,这是我的代码:)

package com.climatedev.WebScraper;

//Import necessary packages
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Document;
import java.net.*;
import java.io.*;
import java.util.Scanner;

//Pull site title and brief description to verify you are getting what you are expecting
public class WikiScraper {
    public static void main(String[] args) {
        Scanner address = new Scanner (System.in);
        System.out.println("Enter the complete url (including http://) of the site you would like to parse:");
        String html = address.nextLine();
        try {
            Document doc = Jsoup.connect(html).get();
            System.out.printf("Title: %s", doc.title());
            //Element table = doc.getElementByID("table");

        } catch (IOException e) {
            e.printStackTrace();
        }
        //Element table = doc.getElementByID("table");
        String contentText = Document.select("#mw-content-text > p").first().text();
    }

}

(})

  ask by Zach Rieck translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...