小编Sim*_*eli的帖子

如何使用 htmlagilitypack 从 html 文档中提取所有链接?

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(s1);

foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
                {
                    count++;
                    HtmlAttribute att = link.Attributes["href"];
                    if (att.Value.StartsWith("http") && !listBox1.Items.Contains(att.Value))
                        listBox1.Items.Add(att.Value);
                }
Run Code Online (Sandbox Code Playgroud)

例如,我得到了 151 个结果,但实际上有超过 300 个。在许多情况下,它发现链接包含多个链接,例如:

href="http://www.test.com dfsdfgfg https://www.test1.com 656567 http://test2.com
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我需要打破它,以便它会显示给我并算作 3 个链接,而不是一个。我试图将 att.Value.StartsWith("http") 更改为 att.Value.Contains("http") 但这不是解决方案。

.net c# winforms

1
推荐指数
1
解决办法
2018
查看次数

为什么我得到异常StackOverFlowException?以及如何解决?

我在form1中添加了一个新表单,我有一个按钮点击事件:

private void button1_Click(object sender, EventArgs e)
        {
            UploadTestingForum utf = new UploadTestingForum();
            utf.Show();
        }
Run Code Online (Sandbox Code Playgroud)

我从这里的示例中获取了新的表单代码:

https://github.com/youtube/api-samples/blob/master/dotnet/UploadVideo.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.IO;
using System.Reflection;
using System.Threading;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

namespace Youtube_Manager
{
    public partial class UploadTestingForum : Form
    {
        string errors = "";

        public UploadTestingForum()
        {
            InitializeComponent();

            try
            {
                new UploadTestingForum().Run().Wait();
            }
            catch (AggregateException ex)
            { …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

-2
推荐指数
1
解决办法
357
查看次数

标签 统计

.net ×2

c# ×2

winforms ×2