Document doc = Jsoup.parse(driver.getPageSource()); // bd m-food-list Elements elements = doc.select("div.m-food-list"); System.out.println(elements.size()); Elements itemList = elements.select("div.m-item"); System.out.println(itemList.size()); for (Element element : itemList) { Elements dl = element.select("dl"); String name = dl.select("dt").text(); System.out.println("店名:"+name); String summer =dl.select("dd.u-txt").text(); System.out.println("摘要:"+summer); String pingfen =dl.select("dd.u-score").text(); System.out.println("评分:"+pingfen); String ads =dl.select("dd.u-ads").text(); System.out.println("地址:"+ads); String phone =dl.select("dd.u-phone").text(); System.out.println("电话 :"+phone); String tag =dl.select("dd.u-tag").text(); System.out.println("标签 :"+tag); }
Elements img = gongsi.select("img"); System.out.println("图片路径 "+img.attr("abs:src")); Elements .attr("href")
public static void web02_jiexieHtml(WebDriver driver ){ Document doc = Jsoup.parse(driver.getPageSource()); Elements container = doc.select("div#listdiv"); // Elements table = container.select("table#MatchTable.socai"); //System.out.println(container.html()); Elements itemList = container.select("div.tab_card"); System.out.println("tab_card数量:"+itemList.size()); Elements aList = container.select("a"); System.out.println("aList数量:"+aList.size()); int index = 0; for(Element item :itemList ){ Elements title = item.select("i.tab_card_job_name"); System.out.println("招聘标题:"+title.get(0).text());//全部 Elements gongzi = item.select("i.tab_card_pay"); System.out.println("招聘工资:"+gongzi.get(0).text());//全部 Elements diqu = item.select("div.newjob_info"); System.out.println("招聘地区经验学历:"+diqu.get(0).text());//全部 Elements fuli = item.select("div.welfare");//这个有可能没有。 if(fuli.size()>0){ System.out.println("招聘福利:"+fuli.get(0).text());//全部 } Elements gongsi = item.select("div.tab_card_bottom");//这个有可能没有。 if(gongsi.size()>0){ Elements img = gongsi.select("img"); System.out.println("图片路径 "+img.attr("abs:src")); System.out.println("招聘公司:"+gongsi.get(0).text());//全部 } } }
Element elementName = element.selectFirst(".answer-user-name");
Document doc = Jsoup.parse(driver.getPageSource()); Elements container = doc.select("div.zwss-item-box"); // Elements table = container.select("table#MatchTable.socai"); //System.out.println(container.html()); Elements itemList = container.select("div.zwss-item"); // System.out.println(itemList.get(0).html()); List<Element> allItem =itemList.get(0).siblingElements();//拿所有的兄弟节点 这里拿兄弟节点不对。 可以直接遍历 itemList -> Element System.out.println(allItem.size()); for(Element item :allItem ){ //System.out.println(item.select("div.zwss-item-job-title").text()); Elements title = item.select("div.zwss-item-job-title"); System.out.println(title.get(0).text());//全部 System.out.println("地区:"+title.get(0).select("span").get(0).text());//地区 System.out.println("更新时间:"+title.get(0).select("span.zwss-item-job-title-time").text());//更新时间 String job = title.get(0).text().replace(title.get(0).select("span").get(0).text(),"").replace(title.get(0).select("span.zwss-item-job-title-time").text(),""); System.out.println("工作:"+job); } // driver = webdriver.Chrome() // driver.get('https://kns.cnki.net/kns/brief/default_result.aspx') # 打开url // input = driver.find_element_by_css_selector('input.rekeyword') // input.send_keys(word) // btn = driver.find_element_by_css_selector('input#btnSearch') // btn.click() // WebElement input = driver.findElement(By.cssSelector(".QKKaIE.LxgeIt")); WebElement btn = driver.findElement(By.cssSelector(".btn-next")); // input.sendKeys("6nlq"); btn.click();
站长微信:xiaomao0055
站长QQ:14496453