Skip to content

encoding problem #358

Description

@zeng-shuo

If the page code is GBK, after calling getpage (URL), occasionally Chinese garbled will appear. How do I set it?

Activity

rbri commented on Jun 17, 2021

@rbri
Member

Can you please provide a bit more details - or better some minimal sample code that shows the porblem.

zeng-shuo commented on Jun 17, 2021

@zeng-shuo
Author

Hello, I'll try to describe the problem as it happens occasionally. For example, the encoding of a web page is set to: < mate content = "text / htmlcharset = GB2312" HTTP equiv = "content type" >, and then I add the following in line 123 of HtmlUnitNekoHtmlParser class in the crawler project:
if (encoding.equals("GB2312")){encoding = "GBK";}
When I use webclient.getPage(URL) to get the HtmlPage and parse it. Sometimes the Chinese on the page is garbled, sometimes not.There are about tens of thousands of requests.

zeng-shuo commented on Jun 18, 2021

@zeng-shuo
Author

Or I want to use GBK code to parse the page, what should I do?

rbri commented on Jun 18, 2021

@rbri
Member

Two points,

  1. GB2312 - GBK
  2. sometimes the result is garbage

Regarding 1.
Because i'm from Germany i only have limited knowledge about all the Chinese codepage stuff. But i did some research and it looks like the jdk handles GB2312 different than browsers. Because of this i like to write a unit test to check the behavior of real browsers and add a fix to HtmlUnit (if needed). But i think i need your help for writing this test - do you like to help here?

Regarding 2.
Sounds like a multi threading issue. Question: do you get this always for the same page?

zeng-shuo commented on Jun 19, 2021

@zeng-shuo
Author

Thank you very much for your help. I changed the new version yesterday, and then optimized the program, there is no garbled code at present. If there is a follow-up I can catch the error, and then reply.

rbri commented on Jun 20, 2021

@rbri
Member

Many thanks for pointing at this - was able to write some test cases and have added a fix.
As a side effect a bunch of other existing tests are working now also.

You can try the latest snapshot - and a release is hopefully available soon.

Again thanks and have fun using HtmlUnit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions