【问题标题】:xidel how to follow pagination html and extract URL?xidel如何跟踪分页html并提取URL?
【发布时间】:2016-05-16 20:34:28
【问题描述】:

在 Windows 7 上批处理和 xidel 我在一个带有分页的网站上进行测试,例如:

链接1

链接2

链接3

1 2 3 4 5 6 7 8 9 10 下一个

我找到了获得前 10 个链接的方法:

xidel.exe https://www.website.es/search?q=xidel+follow+pagination^&start=0 --extract "//a/extract(@href, 'url[?]q=([^&]+)&', 1)[. != '']"

但是当我尝试跟随到第 2 页或第 (n) 页时

-f "<A class="fl">{.}</A>"

--follow "//a/[@class='nav']"

nothink 工作,你能给我一些帮助或一些例子吗?

谢谢。

【问题讨论】:

    标签: windows batch-file pagination xidel


    【解决方案1】:

    雷诺是对的。但是查询谷歌也可以这样:

    xidel -s "https://www.google.com" ^
          -f "form(//form,{'q':'xidel follow pagination','num':'25'})" ^
          -e "//a/extract(@href,'url\?q=(.+?)&',1)[.]"
    

    【讨论】:

    • ^ 在这里做什么?
    • 这似乎不遵循分页。
    • @chovy 我希望你注意到标签windowsbatch-file
    • 是否可以限制页数(用于测试)
    【解决方案2】:
    xidel -s^
      "https://www.google.com/search?q=xidel+follow+pagination&start=0"^
      -e "//a/extract(@href,'url\?q=(.+?)&',1)[.]"^
      -f "(//td/a/@href)[last()]"^
      -e "//a/extract(@href,'url\?q=(.+?)&',1)[.]"
    

    2021 年更新:

    xidel -s^
      --user-agent "Mozilla/5.0 Firefox/94.0.1"^
      -H "Cookie: CONSENT=YES+cb.20210518-05-p0.nl+F+224"^
      "https://www.google.com/search?q=xidel+follow+pagination"^
      -e "//div[@class='yuRUbf']/a/@href"^
      -f "//a[@id='pnnext']/@href"
    

    "https://www.google.com" -f "form(//form,{'q':'xidel follow pagination'})" 也可以)

    五年前在没有用户代理或 cookie 标头的情况下查询 Google 就可以了。现在没有它是行不通的。

    我的原始查询(我是 xidel 新手和所有人)只会从第 1 页和第 2 页中提取网址。-f "//a[@id='pnnext']/@href" 现在在末尾,xidel 将递归地跟踪所有结果页。

    请注意,尽管使用-e "//div[@class='yuRUbf']/a/@href" 提取网址对我有用,但它可能对您不起作用,因为@class 可能有另一个值,最重要的是,会随着时间而变化。 -f "//a[@id='pnnext']/@href" 也是如此。

    【讨论】:

    • 我收到no root element
    • 是否可以递归地跟踪分页中的“下一个”链接,直到它不再存在?
    • @chovy 查看更新后的答案。
    • 似乎不再起作用了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    相关资源
    最近更新 更多