我尝试ul
使用 Jsoup 从上面的页面中获取所有呈现的 html 列表。
这是我的代码:
Document doc = Jsoup.connect("http://www.unc.edu/academics/").get();
Elements lists = doc.select("ul");
for (Element list: lists) {
Elements li = list.select("li a");
if (li.size() > 0) {
ArrayList<String> anchors = new ArrayList<String>();
for (Element e : li) {
anchors.add(e.text());
}
System.out.println(anchors);
}
}
以下是输出:
[Calendar, Libraries, Maps, Departments, MyUNC]
[About UNC, Academics, Research, Public Service, Health Care, UNC Global, Arts, Athletics]
[Academic Departments, Continuing Education, Distance Education, Provost, Services and Resources]
[Academic Calendar, Courses, Libraries, Registrar, Sakai]
[College of Arts & Sciences, Dentistry, Education, Eshelman School of Pharmacy, Friday Center for Continuing Education, General College, Gillings School of Global Public Health, Graduate School, Kenan-Flagler Business School, Government, Information & Library Science, Journalism & Mass Communication, Law, Medicine, Nursing, Social Work, Summer School]
[Departments A-Z, Departments by Interest Area]
[American Indian Studies, APPLES Service-Learning, Applied Sciences & Engineering, Archaeology, Bioinformatics & Computational Biology Training, Biological & Biomedical Sciences, Burch Fellows, Business (Undergraduate), Carolina Entrepreneurial Initiative, Christianity & Culture, Cinema, Cognitive Science, Comparative Literature, Communication Studies, Creative Writing, Cultural Studies, Developmental Biology Training, Ethnicity, Culture & Health Outcomes, Environment & Ecology, European Studies, First Year Seminars, Folklore, Genetics & Molecular Biology, Global Studies, Honors, Humanities & Human Values, Institute for Environment, Jewish Studies, Johnston Center for Undergraduate Excellence, Languages Across Curriculum, Latin American Studies, Latina/o Studies, Management & Society, Mathematical Decision Sciences, Mathematical Sciences, Medieval & Early Modern Studies, Middle East/Muslim Civilizations, Molecular Biology & Biotechnology, Molecular/Cellular Biophysics, Morehead-Cain Scholarship, Neurobiology, Peace, War & Defense, Philosophy, Politics & Economics, Program on Health Outcomes, Public Administration, Public Health Leadership, Russian/East European Studies, Robertson Scholars, Sexuality Studies, Social & Economic Justice, SPIRE Postdoctoral Program, Stone Center, Study Abroad, SURE, Toxicology, Transatlantic Master’s Program, Undergraduate Curricula, World View, Writing for Screen & Stage]
[Alert Carolina, Contact, Departments, Directory, Employment, FAQs, ITS, Privacy Policy, Accessibility, RSS Feeds]
您可能会注意到下图中显示的三个列表正在合并为一个,即输出中的第五个列表。
正如您在页面源代码中看到的那样,这三个列表确实是由三个ul
标签呈现的。它可能与页面中嵌入的 Javascript 或 CSS 有关吗?