Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
innerHTML
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
candidats
innerHTML
Commits
d349c7e4
Commit
d349c7e4
authored
Dec 03, 2017
by
someone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
f9888d74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
getInnerHTML.js
getInnerHTML.js
+45
-0
No files found.
getInnerHTML.js
0 → 100644
View file @
d349c7e4
const
axios
=
require
(
'axios'
);
const
domParser
=
require
(
'dom-parser'
);
const
xpath
=
require
(
'xpath'
);
var
cache
=
{};
async
function
crawler
(
url
,
id
,
cb
)
{
cache
[
url
]
=
cache
[
url
]
?
cache
[
url
]
:
await
axios
.
get
(
url
)
.
catch
(
function
(
e
)
{
console
.
error
(
"Err near the axios.get"
,
e
);
});
return
cb
(
cache
[
url
].
data
,
id
);
}
function
getInnerHTML_example_using_dom_parser
(
x
,
id
)
{
let
r
=
null
;
try
{
let
dp
=
new
domParser
({
errorHandler
:
(
e
)
=>
{
clog
(
e
);
}});
let
xmldoc
=
dp
.
parseFromString
(
x
,
'text/html'
);
let
el
=
xmldoc
.
getElementById
(
id
);
r
=
el
.
innerHTML
;
}
catch
(
e
)
{
console
.
error
(
e
);
}
return
JSON
.
stringify
(
r
);
}
function
getInnerHTML
(
x
,
id
)
{
let
resultAsString
=
null
;
// Please write your code here
// Please don't use any standard or nonstandard DOMParser
return
resultAsString
;
}
(
async
()
=>
{
let
url
=
"https://www.amazon.com/dp/B01I5X5SQE"
let
id
=
'SalesRank'
;
let
r1
=
await
crawler
(
url
,
id
,
getInnerHTML_example_using_dom_parser
);
let
r2
=
await
crawler
(
url
,
id
,
getInnerHTML_example_using_dom_parser
);
console
.
log
(
'Does the "getInnerHTML_example_using_dom_parser" function work correctly?'
,
r1
===
r2
);
let
r3
=
await
crawler
(
url
,
id
,
getInnerHTML
);
console
.
log
(
'Does the "getInnerHTML" function work correctly?'
,
r3
===
r2
);
})()
\ No newline at end of file
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