Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NumEco Ecologie Gouv
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
Numérique et Écologie
NumEco Ecologie Gouv
Commits
b91d8115
Commit
b91d8115
authored
1 year ago
by
CANÉVET Cindy
Browse files
Options
Downloads
Patches
Plain Diff
Ajout de retry dans la récupération des articles (latences)
parent
26853f33
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
Feature/refactoring
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
analysis/analyser/crawler.js
+62
-46
62 additions, 46 deletions
analysis/analyser/crawler.js
with
62 additions
and
46 deletions
analysis/analyser/crawler.js
+
62
−
46
View file @
b91d8115
...
...
@@ -121,7 +121,7 @@ export async function getPolPublics(nb) {
const
url_polpubl
=
`
${
BASE_URL
}
/sitemap.xml?page=6`
;
const
response
=
await
fetch
(
url_polpubl
);
const
data
=
await
response
.
text
();
const
parser
=
await
libxmljs
.
parseXml
(
data
);
const
parser
=
libxmljs
.
parseXml
(
data
);
const
obj_urls
=
parser
.
find
(
"
//*[contains(@href, '/politiques/')]
"
);
for
(
let
link
=
0
;
link
<
obj_urls
.
length
;
link
++
)
{
temp_urls
.
push
(
obj_urls
[
link
].
getAttribute
(
'
href
'
).
value
());
...
...
@@ -221,62 +221,78 @@ async function getArticles({
url
,
nb
,
})
{
const
cpt_timeout
=
3
;
let
cpt
=
0
;
const
urls
=
[];
if
(
nb
<=
0
)
{
return
urls
;
}
console
.
error
(
`Fetching
${
url
}
...`
);
const
response
=
await
fetch
(
url
);
const
data
=
await
response
.
text
();
const
dom
=
new
JSDOM
(
data
);
const
document
=
dom
.
window
.
document
;
const
xpathResult
=
document
.
evaluate
(
xpathNode
,
document
,
null
,
dom
.
window
.
XPathResult
.
ORDERED_NODE_ITERATOR_TYPE
,
null
,
);
let
node
=
xpathResult
.
iterateNext
();
while
(
node
)
{
let
date
=
document
.
evaluate
(
xpathDate
,
node
,
null
,
dom
.
window
.
XPathResult
.
STRING_TYPE
,
null
,
).
stringValue
;
if
(
dateParser
)
{
date
=
dateParser
(
date
);
}
urls
.
push
({
url
:
toAbsoluteUrl
(
document
.
evaluate
(
xpathUrl
,
while
(
true
)
{
try
{
console
.
error
(
`Fetching
${
url
}
...`
);
const
response
=
await
fetch
(
url
);
const
data
=
await
response
.
text
();
const
dom
=
new
JSDOM
(
data
);
const
document
=
dom
.
window
.
document
;
const
xpathResult
=
document
.
evaluate
(
xpathNode
,
document
,
null
,
dom
.
window
.
XPathResult
.
ORDERED_NODE_ITERATOR_TYPE
,
null
,
);
let
node
=
xpathResult
.
iterateNext
();
while
(
node
)
{
let
date
=
document
.
evaluate
(
xpathDate
,
node
,
null
,
dom
.
window
.
XPathResult
.
STRING_TYPE
,
null
,
).
stringValue
,
),
title
:
document
.
evaluate
(
xpathTitle
,
node
,
null
,
dom
.
window
.
XPathResult
.
STRING_TYPE
,
null
,
).
stringValue
,
date
,
});
if
(
urls
.
length
===
nb
)
{
).
stringValue
;
if
(
dateParser
)
{
date
=
dateParser
(
date
);
}
urls
.
push
({
url
:
toAbsoluteUrl
(
document
.
evaluate
(
xpathUrl
,
node
,
null
,
dom
.
window
.
XPathResult
.
STRING_TYPE
,
null
,
).
stringValue
,
),
title
:
document
.
evaluate
(
xpathTitle
,
node
,
null
,
dom
.
window
.
XPathResult
.
STRING_TYPE
,
null
,
).
stringValue
,
date
,
});
if
(
urls
.
length
===
nb
)
{
return
urls
;
}
node
=
xpathResult
.
iterateNext
();
}
return
urls
;
}
catch
(
error
)
{
if
(
cpt
<
cpt_timeout
)
{
cpt
+=
1
;
continue
;
}
else
{
throw
new
Error
(
"
Timeout Error: Navigation Timeout
"
);
break
;
}
}
node
=
xpathResult
.
iterateNext
();
}
return
urls
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment