Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
9
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Jan Klass
Sitemap Crawler
Commits
18721b8a
Commit
18721b8a
authored
Nov 13, 2018
by
Jan Klass
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix
parent
39e68569
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
19 deletions
+27
-19
crawl.jl
crawl.jl
+27
-19
No files found.
crawl.jl
View file @
18721b8a
...
...
@@ -10,21 +10,20 @@ struct CrawlData
CrawlData
()
=
new
(
Set
(),
Set
(),
Set
(),
Set
(),
Set
(),
Set
(),
Set
())
end
function
handlehref
(
data
::
CrawlData
,
base
,
url
,
href
;
forcehttps
=
false
)
# Remove URL fragment (#)
href
=
match
(
r
"^(?<path>[^\#]*)"
,
href
)[
:
path
]
function
getprotocol
(
url
)
match
(
r
"^(?<protocol>[a-zA-Z0-9]+)?\:\/\/"
,
url
)[
:
protocol
]
end
href_protocol
=
match
(
r
"^(?<protocol>[a-zA-Z0-9]+)?\:\/\/"
,
href
)[
:
protocol
]
if
href_protocol
!=
nothing
if
href_protocol
==
"http"
||
href_protocol
==
"https"
if
forcehttps
function
handlehref_abs
(
data
::
CrawlData
,
base
,
url
,
href
,
href_protocol
;
forcehttps
=
false
)
if
href_protocol
==
"http"
&&
forcehttps
href_protocol
=
"https"
href_noprot
=
chop
(
href
;
head
=
length
(
href_protocol
),
tail
=
0
)
ismatch
=
startswith
(
href_noprot
,
base_noprot
)
else
ismatch
=
startswith
(
href
,
base
)
href
=
"https"
*
href_noprot
end
if
href_protocol
==
"http"
||
href_protocol
==
"https"
# Index urls that start with the base URL
if
ismatch
if
startswith
(
href
,
base
)
push!
(
data
.
urls
,
href
)
@debug
"Match (absolute URL):
$
href"
else
...
...
@@ -34,6 +33,15 @@ function handlehref(data::CrawlData, base, url, href; forcehttps=false)
else
@debug
"Ignoring URL
$
href with ignored procotol
$
href_protocol"
end
end
function
handlehref
(
data
::
CrawlData
,
base
,
url
,
href
;
forcehttps
=
false
)
# Remove URL fragment (#)
href
=
match
(
r
"^(?<path>[^\#]*)"
,
href
)[
:
path
]
href_protocol
=
getprotocol
(
href
)
if
href_protocol
!=
nothing
handlehref_abs
(
data
,
base
,
url
,
href
,
href_protocol
)
elseif
startswith
(
href
,
"/"
)
abshref
=
base
*
chop
(
href
;
head
=
1
,
tail
=
0
)
@debug
"Match (absolute path):
$
abshref"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment