本文整理汇总了Java中org.jsoup.nodes.Element.select方法的典型用法代码示例。如果您正苦于以下问题:Java Element.select方法的具体用法?Java Element.select怎么用?Java Element.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
List<AlbumInfo> data = new ArrayList<>();
Document document = Jsoup.parse(new String(result, "utf-8"));
Elements elements = document.select("#post-list-posts li div.inner a:has(img)");
for (Element element : elements) {
AlbumInfo temp = new AlbumInfo();
temp.setAlbumUrl(baseUrl + element.attr("href"));
Elements elements1 = element.select("img");
if (elements1.size() > 0)
temp.setPicUrl("https:" + elements1.get(0).attr("src"));
data.add(temp);
}
resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
resultMap.put(ContentsActivity.parameter.RESULT, data);
return resultMap;
}
示例2: populatePointsGivenToDef
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public void populatePointsGivenToDef(Team team) {
int rankCounter = 0;
Element defPointsAllowedTable = defPointsAllowedURL.select("table").get(0);
Elements defPointsAllowedRows = defPointsAllowedTable.select("tr");
for (int i = 3; i < defPointsAllowedRows.size(); i++) {
Element row = defPointsAllowedRows.get(i);
Elements cols = row.select("td");
rankCounter++;
if(cols.get(0).text().contains(team.getName())) {
if (cols.get(2).text().contains("*")) {
team.setFpToDefRank(rankCounter);
team.setFpToDefAvg(Double.parseDouble(cols.get(18).text()));
break;
} else {
team.setFpToDefRank(rankCounter);
team.setFpToDefAvg(Double.parseDouble(cols.get(19).text()));
break;
}
}
}
}
示例3: getContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
List<AlbumInfo> data = new ArrayList<>();
Document document = Jsoup.parse(new String(result, "utf-8"));
Elements elements = document.select("section");
for (Element element : elements) {
AlbumInfo temp = new AlbumInfo();
Elements album = element.select("a:has(img)");
if (album.size() > 0) {
temp.setAlbumUrl(album.attr("href"));
Elements pic = album.select("img");
if (pic.size() > 0)
temp.setPicUrl(pic.get(0).attr("data-src"));
}
data.add(temp);
}
resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
resultMap.put(ContentsActivity.parameter.RESULT, data);
return resultMap;
}
示例4: getContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
List<AlbumInfo> urls = new ArrayList<>();
Document document = Jsoup.parse(new String(result, "gb2312"));
Elements elements = document.select(".partacpic li a");
for (Element element : elements) {
AlbumInfo temp = new AlbumInfo();
temp.setAlbumUrl(baseUrl + element.attr("href"));
Elements elements1 = element.select("img");
if (elements1.size() > 0) {
temp.setPicUrl(baseUrl + elements1.get(0).attr("src"));
}
urls.add(temp);
}
resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
resultMap.put(ContentsActivity.parameter.RESULT, urls);
return resultMap;
}
示例5: getContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
List<AlbumInfo> data = new ArrayList<>();
Document document = Jsoup.parse(new String(result, "utf-8"));
Elements elements = document.select(".posts_block span.img_block_big>a");
for (Element element : elements) {
AlbumInfo temp = new AlbumInfo();
temp.setAlbumUrl(baseUrl + element.attr("href"));
Elements elements1 = element.select("img");
if (elements1.size() > 0) {
String coverUrl = elements1.get(0).attr("src");
if (coverUrl != null && !"".equals(coverUrl)) {
if (coverUrl.startsWith("https:"))
temp.setPicUrl(coverUrl);
else
temp.setPicUrl("https:" + coverUrl);
}
}
if (temp.getPicUrl() != null && !"".equals(temp.getPicUrl()))
data.add(temp);
}
resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
resultMap.put(ContentsActivity.parameter.RESULT, data);
return resultMap;
}
示例6: getSubjectList
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public List<Subject> getSubjectList() throws IOException {
Element mainContainer = snp.getSnPPageDocument(attendancePageUrl)
.select(".mainContainer #idPrzedmiot").first();
List<Subject> subjectList = new ArrayList<>();
for (Element subject : mainContainer.select("option")) {
subjectList.add(new Subject()
.setId(Integer.parseInt(subject.attr("value")))
.setName(subject.text())
);
}
return subjectList;
}
示例7: call
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Elements call(Element e, List<String> args) {
try {
return Collector.collect(cache.get(args.get(0)), e);
} catch (ExecutionException e1) {
log.warn("error when loader css query rule cache", e1);
}
return e.select(args.get(0));// 发生异常则服务降级
}
示例8: getSingleQueryResult
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private static String getSingleQueryResult(Element soup, String query, boolean toString){
Elements re = soup.select(query);
if(!re.isEmpty()){
if(toString) {
return re.get(0).toString();
}
else{
return re.get(0).text();
}
}else{
return "";
}
}
示例9: selectList
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public List<String> selectList(Element element) {
Elements elements = element.select("a");
List<String> links = new ArrayList<String>(elements.size());
for (Element element0 : elements) {
if (!StringUtil.isBlank(element0.baseUri())) {
links.add(element0.attr("abs:href"));
} else {
links.add(element0.attr("href"));
}
}
return links;
}
示例10: append
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private int append(Element node, StringBuilder sb, String tagName) {
int countOfP = 0; // Number of P elements in the article
int paragraphWithTextIndex = 0;
// is select more costly then getElementsByTag?
MAIN:
for (Element e : node.select(tagName)) {
Element tmpEl = e;
// check all elements until 'node'
while (tmpEl != null && !tmpEl.equals(node)) {
if (unlikely(tmpEl))
continue MAIN;
tmpEl = tmpEl.parent();
}
String text = node2Text(e);
if (text.isEmpty() || text.length() < getMinParagraph(paragraphWithTextIndex)
|| text.length() > SHelper.countLetters(text) * 2) {
continue;
}
if (e.tagName().equals("p")) {
countOfP++;
}
sb.append(text);
sb.append("\n\n");
paragraphWithTextIndex += 1;
}
return countOfP;
}
示例11: getDefinition
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
static public YoudaoResult getDefinition(String key) throws IOException{
Document doc = Jsoup.connect(String.format(BASE_URL, key.trim()))
.userAgent("Mozilla")
.cookie("auth", "token")
.timeout(2000)
.parser(Parser.xmlParser())
.get();
//doc.toString();
String phonetic = getSingleQueryResult(doc, "phonetic-symbol");
String returnPhrase = getSingleQueryResult(doc, "return-phrase");
List<String> translation = new ArrayList<String>();
for(Element e : doc.select("translation > content")){
translation.add(e.text());
}
Map<String, List<String>> webTranslation = new LinkedHashMap<>();
for(Element web : doc.select("web-translation")){
String keyString = getSingleQueryResult(web, "key");
List<String> values = new ArrayList<>();
for(Element value : web.select("trans > value")){
String valueString = value.text().trim();
values.add(valueString);
}
webTranslation.put(keyString, values);
}
YoudaoResult youdaoResult = new YoudaoResult();
youdaoResult.phonetic = phonetic;
youdaoResult.returnPhrase = returnPhrase;
youdaoResult.translation = translation;
youdaoResult.webTranslation = webTranslation;
return youdaoResult;
}
示例12: getTypesTable
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public Types getTypesTable(String tick, Integer subjectId) throws IOException {
Element mainContainer = snp.getSnPPageDocument((attendancePageUrl
+ "?data={tick}&idPrzedmiot={subject}")
.replace("{tick}", tick)
.replace("{subject}", subjectId.toString())
).select(".mainContainer").first();
Element table = mainContainer.select("table:nth-of-type(2)").first();
Elements headerCells = table.select("thead th");
List<Type> typeList = new ArrayList<>();
Elements typesRows = table.select("tbody tr");
// fill types with months
for (Element row : typesRows) {
Elements monthsCells = row.select("td");
List<Month> monthList = new ArrayList<>();
// iterate over month in type, first column is empty, last is `total`; (0, n-1)
for (int i = 1; i < monthsCells.size() - 1; i++) {
monthList.add(new Month()
.setValue(NumberUtils.toInt(monthsCells.get(i).text(), 0))
.setName(headerCells.get(i).text()));
}
typeList.add(new Type()
.setTotal(NumberUtils.toInt(monthsCells.last().text(), 0))
.setName(monthsCells.get(0).text())
.setMonthList(monthList));
}
String total = mainContainer.select("h2").text().split(": ")[1];
return new Types()
.setTotal(NumberUtils.toDouble(total.replace("%", "").replace(",", ".")))
.setTypeList(typeList);
}
示例13: doAnalysis
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public List doAnalysis(String html) {
List<TermTeacherCoursePageBo> list = new ArrayList<TermTeacherCoursePageBo>();
if(html!=null){
Document doc = Jsoup.parse(html);
Element table = HTMLUtil.getTableByTableHeadWords(doc, headwords);
//开始解析
Elements trs = table.select("tr:gt(0)");
TermTeacherCoursePageBo preCourse=null;
for(Element tr:trs){
Elements tds = tr.select("td");
if(tds.size()<10) continue;
String tempCourse= tds.get(1).text().trim();
String tempCredit = tds.get(2).text().trim();
String tempTeachingWay=tds.get(3).text().trim();
String tempCourseType=tds.get(4).text().trim();
String tempCourseClassNo= tds.get(5).text().trim();
String tempClassName = tds.get(6).text().trim();
String tempStudentNum= tds.get(7).text().trim();
String tempTime= tds.get(8).text().trim();
String tempClassroom= tds.get(9).text().trim();
if(tempCourse == null ||tempCourse.equals("")){
preCourse = list.get(list.size()-1);
tempCourse = preCourse.getCourse();
if(tempCredit == null ||tempCredit.equals("")){
tempCredit = preCourse.getCredit();
}
if(tempTeachingWay == null ||tempTeachingWay.equals("")){
tempTeachingWay = preCourse.getTeachingWay();
}
if(tempCourseClassNo == null ||tempCourseClassNo.equals("")){
tempCourseClassNo = preCourse.getCourseClassNo();
}
if(tempCourseType == null ||tempCourseType.equals("")){
tempCourseType = preCourse.getCourseType();
}
if(tempClassName == null ||tempClassName.equals("")){
tempClassName = preCourse.getClassName();
}
if(tempStudentNum == null ||tempStudentNum.equals("")){
tempStudentNum = preCourse.getStudentNum();
}
if(tempClassroom == null ||tempClassroom.equals("")){
tempClassroom = preCourse.getClassroom();
}
}
TermTeacherCoursePageBo termTeacherCoursePageBo= new TermTeacherCoursePageBo();
termTeacherCoursePageBo.setClassName(tempClassName);
termTeacherCoursePageBo.setClassroom(tempClassroom);
termTeacherCoursePageBo.setCourseType(tempCourseType);
termTeacherCoursePageBo.setCourseClassNo(tempCourseClassNo);
termTeacherCoursePageBo.setCourse(tempCourse);
termTeacherCoursePageBo.setTime(tempTime);
termTeacherCoursePageBo.setCredit(tempCredit);
termTeacherCoursePageBo.setTeachingWay(tempTeachingWay);
termTeacherCoursePageBo.setStudentNum(tempStudentNum);
termTeacherCoursePageBo.setTerm(getTerm());
termTeacherCoursePageBo.setTeacher(getTeacher());
list.add(termTeacherCoursePageBo);
}
}
return list;
}
示例14: loadGitTrending
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static List<Repository> loadGitTrending(String lan) throws SocketTimeoutException {
List<Repository> list = Lists.newArrayList();
try {
Document doc = Jsoup.connect(StaticConfig.Host.GITHUB + "/trending/" + lan).get();
Elements elements = doc.select(".repo-list > li");
for (Element element : elements) {
String title = "";
String link = "";
String descr = "";
Elements titles = element.select(".d-inline-block > h3 > a");
for (Element titleElement : titles) {
title = titleElement.text();
link = titleElement.attr("href");
}
LOGGER.info("[title]" + title);
LOGGER.info("[link]" + link);
Elements descrElements = element.select(".py-1 > p");
for (Element descrElement : descrElements) {
descr = descrElement.text();
}
LOGGER.info("[description]" + descr);
list.add(Repository.builder().language(lan).title(title).link(StaticConfig.Host.GITHUB + link)
.description(descr).module(lan).build());
}
System.err.println("---------------------------------------");
for (Repository repository : list) {
LOGGER.info(repository.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
示例15: extractLink
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public String extractLink(Element td) {
Elements href = td.select("a");
if (!href.isEmpty()) {
//<i><a href="/wiki/1001_Spikes" title="1001 Spikes">1001 Spikes</a></i>
return href.attr("href");
}
return null;
}