gpt4 book ai didi

c# - 如何让 scrapysharp 在 MVC 网络应用程序中工作?

转载 作者:行者123 更新时间:2023-11-30 21:46:17 25 4
gpt4 key购买 nike

我成功地让 scrapysharp 在控制台应用程序中工作。

我在 VS2013 中创建了一个新的 MVC 网络应用程序,没有身份验证或任何其他特殊内容。我使用 nuget 添加了 ScrapySharp,然后在我的 Home Controller 中添加了这段代码。我的页面结果没有任何回应。有谁知道为什么?如何让 scrapysharp 在 MVC 网络应用程序中工作?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ScrapySharp.Html.Forms;
using ScrapySharp.Network;
using ScrapySharp;
using HtmlAgilityPack;
using ScrapySharp.Extensions;

namespace scrapyB.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
var browser = new ScrapingBrowser();
browser.AllowAutoRedirect = true;
browser.AllowMetaRedirect = true;
var pageresult = browser.NavigateToPage(new Uri("https://google.com"));
var x = pageresult;
return View();
}

public ActionResult About()
{
ViewBag.Message = "Your application description page.";

return View();
}

public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";

return View();
}
}
}

编辑实际上,我只是尝试了一个 Windows 窗体应用程序,而 NavigateToPage 也没有返回结果。这很奇怪,但它似乎只适用于控制台应用程序。有谁知道如何让 ScrapySharp 在控制台应用程序以外的地方工作?

最佳答案

好的,scrapysharp 有一个 NavigateToPageAsync 函数。这会返回预期的结果。

Form.submit() 也使用 NavigateToPage,但您可以改用 NavigateToPageAsync 并传入正确的参数以提交表单。

关于c# - 如何让 scrapysharp 在 MVC 网络应用程序中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39379037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com