Truncated text when using HtmlUnit to save complete page
I've tried to save the complete page using Java or Python and I also have tried selenium and wget.
Finally I've chosen HtmlUnit because it can be easily achieved by using save().
My page is getting truncated, the Chinese characters show as "?".
Is there any way to change the encoding? Or there have any other tools to save the complete page?
My code:
WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
try {
HtmlPage htmlPage = webClient.getPage("http://www.fulijr.com/");
File file = new File("fulijr.html");
htmlPage.save(file);
} catch (IOException e) {
e.printStackTrace();
}
The result:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
<meta name="keywords" content="????,????????,??????P2P????"/>
<meta name="description" content="??????????P2P???????????????????????????????????????????????????????????????????????????????????P2P???????????????????????????????????????????????????????????????????????????"/>
...
java python web-crawler
add a comment |
I've tried to save the complete page using Java or Python and I also have tried selenium and wget.
Finally I've chosen HtmlUnit because it can be easily achieved by using save().
My page is getting truncated, the Chinese characters show as "?".
Is there any way to change the encoding? Or there have any other tools to save the complete page?
My code:
WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
try {
HtmlPage htmlPage = webClient.getPage("http://www.fulijr.com/");
File file = new File("fulijr.html");
htmlPage.save(file);
} catch (IOException e) {
e.printStackTrace();
}
The result:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
<meta name="keywords" content="????,????????,??????P2P????"/>
<meta name="description" content="??????????P2P???????????????????????????????????????????????????????????????????????????????????P2P???????????????????????????????????????????????????????????????????????????"/>
...
java python web-crawler
You have to do something like this (like in Fetch class): stackoverflow.com/a/44493023/4392611 and before saving read encoding declaration, otherwise it makes no sense.
– Zydnar
Nov 23 '18 at 14:03
add a comment |
I've tried to save the complete page using Java or Python and I also have tried selenium and wget.
Finally I've chosen HtmlUnit because it can be easily achieved by using save().
My page is getting truncated, the Chinese characters show as "?".
Is there any way to change the encoding? Or there have any other tools to save the complete page?
My code:
WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
try {
HtmlPage htmlPage = webClient.getPage("http://www.fulijr.com/");
File file = new File("fulijr.html");
htmlPage.save(file);
} catch (IOException e) {
e.printStackTrace();
}
The result:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
<meta name="keywords" content="????,????????,??????P2P????"/>
<meta name="description" content="??????????P2P???????????????????????????????????????????????????????????????????????????????????P2P???????????????????????????????????????????????????????????????????????????"/>
...
java python web-crawler
I've tried to save the complete page using Java or Python and I also have tried selenium and wget.
Finally I've chosen HtmlUnit because it can be easily achieved by using save().
My page is getting truncated, the Chinese characters show as "?".
Is there any way to change the encoding? Or there have any other tools to save the complete page?
My code:
WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
try {
HtmlPage htmlPage = webClient.getPage("http://www.fulijr.com/");
File file = new File("fulijr.html");
htmlPage.save(file);
} catch (IOException e) {
e.printStackTrace();
}
The result:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
<meta name="keywords" content="????,????????,??????P2P????"/>
<meta name="description" content="??????????P2P???????????????????????????????????????????????????????????????????????????????????P2P???????????????????????????????????????????????????????????????????????????"/>
...
java python web-crawler
java python web-crawler
edited Nov 23 '18 at 11:30
user6490459
asked Nov 23 '18 at 10:13
C.shayvC.shayv
162
162
You have to do something like this (like in Fetch class): stackoverflow.com/a/44493023/4392611 and before saving read encoding declaration, otherwise it makes no sense.
– Zydnar
Nov 23 '18 at 14:03
add a comment |
You have to do something like this (like in Fetch class): stackoverflow.com/a/44493023/4392611 and before saving read encoding declaration, otherwise it makes no sense.
– Zydnar
Nov 23 '18 at 14:03
You have to do something like this (like in Fetch class): stackoverflow.com/a/44493023/4392611 and before saving read encoding declaration, otherwise it makes no sense.
– Zydnar
Nov 23 '18 at 14:03
You have to do something like this (like in Fetch class): stackoverflow.com/a/44493023/4392611 and before saving read encoding declaration, otherwise it makes no sense.
– Zydnar
Nov 23 '18 at 14:03
add a comment |
1 Answer
1
active
oldest
votes
This is a bug in the current version of HtmlUnit (version 2.33). Have fixed this; will inform on https://twitter.com/HtmlUnit if a new snapshot build is available.
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444689%2ftruncated-text-when-using-htmlunit-to-save-complete-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a bug in the current version of HtmlUnit (version 2.33). Have fixed this; will inform on https://twitter.com/HtmlUnit if a new snapshot build is available.
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
add a comment |
This is a bug in the current version of HtmlUnit (version 2.33). Have fixed this; will inform on https://twitter.com/HtmlUnit if a new snapshot build is available.
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
add a comment |
This is a bug in the current version of HtmlUnit (version 2.33). Have fixed this; will inform on https://twitter.com/HtmlUnit if a new snapshot build is available.
This is a bug in the current version of HtmlUnit (version 2.33). Have fixed this; will inform on https://twitter.com/HtmlUnit if a new snapshot build is available.
answered Nov 24 '18 at 20:09
RBRiRBRi
1,3662610
1,3662610
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
add a comment |
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
Thanks, I have tried build 2.34-SNAPSHOT and it's work.
– C.shayv
Nov 26 '18 at 1:18
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
When is the release for this 2.34 coming out?
– Sulaiman Adeeyo
Jan 16 at 14:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444689%2ftruncated-text-when-using-htmlunit-to-save-complete-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have to do something like this (like in Fetch class): stackoverflow.com/a/44493023/4392611 and before saving read encoding declaration, otherwise it makes no sense.
– Zydnar
Nov 23 '18 at 14:03