You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var dom = CQ.CreateFromUrl("http://www.cnbeta.com/articles/222432.htm");
var node = dom.Select("#news");
string html = HttpUtility.HtmlDecode(node.Html());
it's looks like the logic of get encoding has some problem.
cannot just set the default encoding to ISO-8859-1.
i had tried to fix it, but the sourcecodes cannot pass buliding.
Error 1 Source file 'HtmlParserSharp\HtmlParserSharp\Common\Attributes.cs' could not be found D:\Test Projects\CsQuery-master\source\CsQuery\CSC CsQuery
Are you saying that "ISO-8859-1" is not a valid encoding in your environment?
Also btw - the compiling problem is because HtmlParserSharp is a submodule, it needs to be initialized separately - there are instructions in the main readme.
OK I think I fixed this in the last push. So now the character set will be detected in the following way:
From the mime type of the HTTP response
From an http-equiv tag
If neither are present from the BOM
If there is no BOM, then UTF8
By the way I don't want to add an encoding parameter for CreateFromUrl because I am not sure how useful it is. You really don't know what the encoding of a remote resource is until you access it and inspect the headers and the stream. Also, you can always use Create(Stream stream, Encoding encoding) if you want to specify an arbitrary encoding, and get the stream yourself
Are you saying that if valid byte order marks are found then the mime type and http-equiv should be ignored?
Btw did you try the update? I think the problem you were having is just my incorrect use of the latin-1 charset. If the character set requested by the headers is not available it will still fall back on the BOM or UTF8.
OK - awesome, glad it worked. There have been a lot of changes to the character set handling in the last couple weeks based on feedback from you and a few others, I hope to get this into a release soon.
Activity
jensenbyte commentedon Jan 16, 2013
my sugesstion:
you can ref the HttpClient or HtmlAgilityPack.
hope the team doing well.
jamietre commentedon Jan 16, 2013
Are you saying that "ISO-8859-1" is not a valid encoding in your environment?
Also btw - the compiling problem is because
HtmlParserSharpis a submodule, it needs to be initialized separately - there are instructions in the main readme.jamietre commentedon Jan 16, 2013
OK I think I fixed this in the last push. So now the character set will be detected in the following way:
By the way I don't want to add an encoding parameter for
CreateFromUrlbecause I am not sure how useful it is. You really don't know what the encoding of a remote resource is until you access it and inspect the headers and the stream. Also, you can always useCreate(Stream stream, Encoding encoding)if you want to specify an arbitrary encoding, and get the stream yourselfjensenbyte commentedon Jan 17, 2013
i agree with your most mind.
but the problem is the mime type and http-equiv tag are not reliable.
only the stream and bytes are reliable to detect the right encoding.
jamietre commentedon Jan 17, 2013
Are you saying that if valid byte order marks are found then the mime type and http-equiv should be ignored?
Btw did you try the update? I think the problem you were having is just my incorrect use of the latin-1 charset. If the character set requested by the headers is not available it will still fall back on the BOM or UTF8.
jensenbyte commentedon Jan 18, 2013
yes, i think the encoding info from http-equiv or http header maybe isn't match to the encoding of contents.
I got the new sourcecode, it's ok now.
well done. thanks you very much.
my os: win8 english, system locale: chinese(simplified, china)
jamietre commentedon Jan 18, 2013
OK - awesome, glad it worked. There have been a lot of changes to the character set handling in the last couple weeks based on feedback from you and a few others, I hope to get this into a release soon.
jamietre commentedon Feb 6, 2013
In release 1.3.4