【问题标题】:C# ScrapySharp 'System.Net.CookieException: 'The 'Name'='HttpOnly, NID' part of the cookie is invalid.'C# ScrapySharp 'System.Net.CookieException: ''Name'='HttpOnly, NID' 部分的 cookie 无效。'
【发布时间】:2019-08-02 20:09:21
【问题描述】:

所以我的代码遇到了一个意想不到的问题。出于某种原因,我无法从我的 Google 搜索中下载和打印链接...非常感谢帮助,因为我真的不确定这里发生了什么...我也在使用 DotNET SDK

using System;
using System.Threading.Tasks;
using ScrapySharp;
using ScrapySharp.Extensions;
using ScrapySharp.Network;
using static System.Console;
namespace Test
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var query = "scrapysharp";
            Console.WriteLine($"Searching '{query}' on google");

            var browser = new ScrapingBrowser();
            browser.UseDefaultCookiesParser = false;
            var resultsPage = await browser.NavigateToPageAsync(new Uri($"https://www.google.fr/search?q={query}"));

            Console.WriteLine($"Results");

            foreach (var link in resultsPage.Html.CssSelect("h3.r a"))
            {
                Console.WriteLine($"- {link.InnerText}");
            }
        }
    }

错误:

System.Net.CookieException: 'The 'Name'='HttpOnly, NID' part of the cookie is invalid.'

【问题讨论】:

    标签: c# scrapysharp


    【解决方案1】:

    我遇到了同样的问题,我的快速解决方法是下面一行代码。

    browser.IgnoreCookies = true;
    

    保留其他所有内容,在您创建浏览器对象的行之后添加这一行并尝试一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 2017-10-25
      • 2019-08-03
      相关资源
      最近更新 更多