简体   繁体   English

无法执行 jSoup Parser

[英]Can´t execute jSoup Parser

I have been looking for information in order to use jSoup so that I can extract some elements from another website, but I can't make it run.我一直在寻找信息以使用jSoup,以便我可以从另一个网站提取一些元素,但是我无法运行它。

I have installed Java and Maven, I created a Java file and then a pom.xml dependency, but when I execute it on Terminal (I'm using Mac), it gives me errors.我已经安装了 Java 和 Maven,我创建了一个 Java 文件,然后创建了一个 pom.xml 依赖项,但是当我在终端(我使用的是 Mac)上执行它时,它给了我错误。

错误

I'm totally lost.我完全迷路了。 I can't even run a simple code so that I can start understanding.我什至不能运行一个简单的代码来开始理解。 I have make several google search but all the tutorials start over a basic knowledge.我已经进行了几次谷歌搜索,但所有的教程都是从基本知识开始的。

I would appreciate if you could tell me where could I start from 0 knowledge, because I´m getting desperate.如果您能告诉我从 0 知识开始我可以从哪里开始,我将不胜感激,因为我快绝望了。

The pom.xml file describes your project so that Maven knows how to compile it. pom.xml 文件描述了您的项目,以便 Maven 知道如何编译它。 At a minimum you need to define your project's group ID, artifact ID, and version--the Maven "coordinates."您至少需要定义项目的组 ID、工件 ID 和版本——Maven“坐标”。 If your project requires libraries, like jsoup, then you can include a <dependencies> section with a <dependency> for each library.如果您的项目需要库,例如 jsoup,那么您可以为每个库包含一个 <dependencies> 部分和一个 <dependency>。 I think you've gotten this far.我想你已经到了这一步。

Maven expects the project to have a certain structure. Maven 期望项目具有一定的结构。

  • You should have a directory with the pom.xml in it.您应该有一个包含 pom.xml 的目录。
  • You should have a subdirectory called "src"您应该有一个名为“src”的子目录
  • Within the "src" directory, you should have a directory called "main"在“src”目录中,您应该有一个名为“main”的目录
  • Within "main," you should have a subdirectory called "java"在“main”中,您应该有一个名为“java”的子目录
  • Within "java," Java source files live in directories that correspond to their packages, so if you have "package com.manuelsagra.laxtore" for class App then that goes in (the directory with pom.xml)/src/main/java/com/manuelsagra/laxtore/App.java.在“java”中,Java 源文件位于与其包相对应的目录中,因此如果您有类 App 的“包 com.manuelsagra.laxtore”,那么它会进入(带有 pom.xml 的目录)/src/main/java /com/manuelsagra/laxtore/App.java。

Sorry if some of this is review for you.对不起,如果其中一些是对您的评论。

You should run Maven (mvn) from the top directory containing pom.xml:您应该从包含 pom.xml 的顶级目录运行 Maven (mvn):

$ mvn install

That should download jsoup and compile anything in src/main/java.那应该下载 jsoup 并编译 src/main/java 中的任何内容。

Then you can run "mvn exec:java ..." from the same directory.然后您可以从同一目录运行“mvn exec:java ...”。

You didn't need maven in order to run JSoup, you can:你不需要 maven 来运行 JSoup,你可以:

  1. download the jsoup jar from jsoup.org ,jsoup.org下载jsoup jar
  2. put it to the project classpath (eg. add jar to netbeans project )将其放入项目类路径(例如,将 jar 添加到 netbeans 项目
  3. import jsoup in your class在您的班级中导入jsoup

and you're good to go.你可以走了。

with maven与行家

  1. create a Maven project (eg maven-quickstart ) the process could be slightly different depending on the IDE that you're using.创建 Maven 项目(例如maven-quickstart )该过程可能会略有不同,具体取决于您使用的 IDE。
  2. add the jsoup dependencies to the pom, by either following the instruction in the link above, or editing the POM.xml , so it looks :通过按照上面链接中的说明或编辑POM.xml将 jsoup 依赖项添加到 pom,因此它看起来像:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yourorgaaniztion</groupId>
    <artifactId>jsoup-with-maven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.10.1</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

the project structure (pom.xml location) should looks like:项目结构(pom.xml 位置)应如下所示: 在此处输入图片说明

I would appreciate if you could tell me where could I star from 0 knowledge, >because I´m getting desperate.如果您能告诉我从 0 知识开始我可以在哪里出演,我将不胜感激,>因为我快绝望了。

from this point, I think you could continue with this mkyong tutorial从这一点来说,我想你可以继续这个 mkyong 教程

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

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