我使用这段代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
namespace HtmlParser
{
public partial class Form1 : Form
{
// The HtmlWeb class is a utility class to get the HTML over HTTP
HtmlWeb htmlWeb = new HtmlWeb();
// Creates an HtmlDocument object from an URL
HtmlAgilityPack.HtmlDocument document;
// Targets a specific node
HtmlNode someNode;
public Form1()
{
InitializeComponent();
document = htmlWeb.Load("http://www.walla.co.il");
someNode = document.GetElementbyId("mynode");
// If there is no node with that Id, someNode will be null
if (someNode != null)
{
// Extracts all links within that node
IEnumerable<HtmlNode> allLinks = someNode.Descendants("a");
// Outputs the href for external links
foreach (HtmlNode link in allLinks)
{
// Checks whether the link contains an HREF attribute
if (link.Attributes.Contains("href"))
{
// Simple check: if the href begins with "http://", prints it out
if (link.Attributes["href"].Value.StartsWith("http://"))
richTextBox1.Text = link.Attributes["href"].Value.ToString();
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
但它永远不会超过这条线:
someNode = document.GetElementbyId("mynode");
在这一行上使用了一个断点,它给了我一条消息:没有可用的源如果我没有使用断点,则程序正在运行,但我没有收到任何错误,但它也不起作用。
我应该怎么办 ?我不明白我应该放什么而不是“我的节点”