1

So i'm facing an unexpected issue with my code. For some reason, I am unable to download & print the links out of my Google search... Help is much appreciated as I'm really not sure what is going on here... I am also using the 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}");
            }
        }
    }

Error:

System.Net.CookieException: 'The 'Name'='HttpOnly, NID' part of the cookie is invalid.'
VillageTech
  • 1,968
  • 8
  • 18

1 Answers1

2

I was facing the same issue, the quick workaround for me was bellow one line code.

browser.IgnoreCookies = true;

Leave everything else as is, add this line after the line where you are creating browser object and try it out.

Junaid Khan
  • 520
  • 6
  • 15