英文:
How do I find the right selector when scraping a website with jSoup?
问题
String url = "https://www.centralcharts.com/en/price-list-ranking/ALL/asc/ts_29-us-nyse-stocks--qc_1-alphabetical-order";
Document doc = Jsoup.connect(url).userAgent("Jsoup Scraper").get();
String stock = "tr:nth-of-type(1) > .footable-first-visible";
Elements stockName = doc.select(stock);
List<String> stocks = new ArrayList<String>();
for (Element e : stockName)
{
stocks.add(e.text());
}
for (String s : stocks) {
System.out.println(s);
}
Please let me know if you need further assistance.
英文:
I am currently learning how to web scrape and am using jSoup to do so. I read the jSoup cookbook on how to do so and followed it's steps. I made sure the source code for the website prints, making sure that is working and is correct. But when I have to find a selector for looping through a websites table, I don't know what to look for, or what to select. I will leave my code below, though I just would like to know what to look for.
String url = "https://www.centralcharts.com/en/price-list-ranking/ALL/asc/ts_29-us-nyse-stocks--qc_1-alphabetical-order";
Document doc = Jsoup.connect(url).userAgent("Jsoup Scraper").get();
String stock = "tr:nth-of-type(1) > .footable-first-visible";
Elements stockName = doc.select(stock);
List<String> stocks = new ArrayList<String>();
for (Element e : stockName)
{
stocks.add(e.text());
}
for (String s : stocks) {
System.out.println(s);
}
专注分享java语言的经验与见解,让所有开发者获益!
评论