沙滩星空的博客沙滩星空的博客

使用goquery和css选择器解析html

起因

之前一直用得好好的 "github.com/antchfx/htmlquery" 解析器突然怎么都提取不出数据,而通过 Chrome 谷歌浏览器的控制台调试时,则解析正常。更换解析器 github.com/PuerkitoBio/goquery 则正常

css选择器

File input = new File("/tmp/input.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");

Elements links = doc.select("a[href]"); //带有href属性的a元素
Elements pngs = doc.select("img[src$=.png]");
  //扩展名为.png的图片

Element masthead = doc.select("div.masthead").first();
  //class等于masthead的div标签

Elements resultLinks = doc.select("h3.r > a"); //在h3元素之后的a元素

goquery


使用cssQuery选择器语法来查找元素 https://www.cnblogs.com/printN/p/6970608.html
goquery的使用 https://blog.csdn.net/yang731227/article/details/89338745

未经允许不得转载:沙滩星空的博客 » 使用goquery和css选择器解析html

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址