所以我的代码遇到了一个意想不到的问题。出于某种原因,我无法从我的 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.'