Note : A similar question has been asked at JSoup:How to Parse a Specific Link. However, I have a more specific variation of this question - Please read ahead
要解析特定站点链接,我需要使用Document
select()
方法以最有效的方式获取此数据。我应该使用什么选择器 CSS 查询来实现此目的?
这是我未编译的尝试之一:
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
import org.jsoup.Connection.*;
import java.io.*;
import java.util.*;
public class WebInteraction {
public Document accLogin(Account ac, String url) {
Document doc;
doc = Jsoup.connect(url).data("name", ac.username, "code", ac.pass).method(Method.POST).execute().parse();
Elements verify = doc.select(a[href*="/logout"]);
}
}
错误信息:
$ javac WebInteraction.java
WebInteraction.java:17: error: cannot find symbol
Elements verify = doc.select(a[href*="/logout"]);
^
symbol: variable a
location: class WebInteraction
WebInteraction.java:17: error: cannot find symbol
Elements verify = doc.select(a[href*="/logout"]);
^
symbol: variable href
location: class WebInteraction
2 errors
最佳答案
以下行存在语法错误:
Elements verify = doc.select(a[href*="/logout"]);
修改如下:
Elements verify = doc.select("a[href*=/logout]");
/logout
不需要双引号。
关于css - 如何使用选择器 CSS 查询解析特定链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38232682/