本文整理匯總了Java中org.jsoup.nodes.Document.getElementsByAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getElementsByAttribute方法的具體用法?Java Document.getElementsByAttribute怎麽用?Java Document.getElementsByAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jsoup.nodes.Document
的用法示例。
在下文中一共展示了Document.getElementsByAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import org.jsoup.nodes.Document; //導入方法依賴的package包/類
@Override
public void process(final ExecutionContext executionContext, final Document document)
throws ProcessException {
try {
Elements xkSections = document.getElementsByAttribute(XK_SECTION_ATTR);
if (xkSections != null) {
for (Element xkSectionTag : xkSections) {
Element xkSectionStylesTag = xkSectionTag.getElementsByAttribute(XK_SECTION_STYLES_ATTR).first();
if (xkSectionStylesTag != null) {
String xkSectionStyles = xkSectionStylesTag.attr(XK_SECTION_STYLES_ATTR);
xkSectionTag.addClass(xkSectionStyles.trim());
xkSectionStylesTag.remove();
}
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例2: call
import org.jsoup.nodes.Document; //導入方法依賴的package包/類
public List<HouseInfo> call() {
lstHouseInfo = new ArrayList<HouseInfo>();
CloseableHttpClient client = HttpClients.createDefault();
Lock lock = new ReentrantLock();
HttpGet get = new HttpGet(url);
//設置請求頭
get.setHeader("Accept", "text/html, application/xhtml+xml, image/jxr, */*");
get.setHeader("Accept-Language", "zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3");
get.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
try{
//獲取響應
CloseableHttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
String html = EntityUtils.toString(entity, "UTF-8");
//解析html
Document doc = Jsoup.parse(html);
Elements lists = doc.getElementsByAttribute("logr");
lock.lock();
try{
for (Element list : lists) {
//將關鍵信息提取出來
HouseInfo houseInfo = new HouseInfo();
String[] houseInfoArray = list.getElementsByTag("h2").first().text().split(" ");
houseInfo.setHouseTitle(list.getElementsByTag("h2").first().text());
houseInfo.setHouseURL("http://" + "bj" + ".58.com" + list.getElementsByTag("a").first().attributes().get("href"));
houseInfo.setMoney(list.getElementsByClass("money").tagName("b").text());
houseInfo.setHouseLocation(houseInfoArray[1]);
lstHouseInfo.add(houseInfo);
}
}finally {
lock.unlock();
}
}catch (IOException e){
System.out.println( e.getMessage());
}
return lstHouseInfo;
}