Created
April 21, 2014 13:51
-
-
Save joewiz/11143323 to your computer and use it in GitHub Desktop.
Check a remote webpage for broken links, with XQuery and EXPath HTTP Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
import module namespace http = "http://expath.org/ns/http-client"; | |
let $url := 'http://history.state.gov/education/modules/border-vanishes-intro' | |
let $links := doc($url)//*:a[ends-with(@href, '.pdf')] | |
return | |
<results n="{count($links)}">{ | |
for $link in $links | |
let $href := if (starts-with($link/@href, '//')) then concat('http:', $link/@href) else $link/@href/string() | |
let $request := <http:request href="{$href}" method="head"/> | |
let $response := http:send-request($request) | |
return | |
<link> | |
<url>{$href}</url> | |
<status>{$response/@status/string()}</status> | |
</link> | |
}</results> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment