dotnetcore / DotnetSpider

DotnetSpider, a .NET standard web crawling library. It is lightweight, efficient and fast high-level web crawling & scraping framework
MIT License
3.98k stars 1.04k forks source link

在DataParser类中的HandleAsync方法中,调用ReadAsString方法时默认编码为UTF-8,如果网页编码为GBK时,在DataParser的子类中实现Parse后,DataContext.Selectable为乱码,无法直接使用。 #175

Closed null-ed closed 4 years ago

null-ed commented 4 years ago

在DataParser类中的HandleAsync方法中,调用ReadAsString方法时默认编码为UTF-8,如果网页编码为GBK时,在DataParser的子类中实现Parse后,DataContext.Selectable为乱码,无法直接使用。 image

zlzforever commented 4 years ago

这个问题已经考虑到了,自己注册一下 SelectableBuilder 处理就好

null-ed commented 4 years ago

这个问题已经考虑到了,自己注册一下SelectableBuilder处理就好

可以举例具体如何使用吗?谢谢!

zlzforever commented 4 years ago
    class MyDataParser : DataParser
    {
        public MyDataParser()
        {
            AddRequiredValidator("cnblogs\\.com");
            AddFollowRequestQuerier(Selectors.XPath("."));

            SelectableBuilder = context =>
            {
                var bytes = context.Response.Content.Data;
                var text = bytes.ToText();
                return new HtmlSelectable(text, null, true);
            };
        }