我正在使用此代码:
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");
在这一行使用断点,它给我一条消息:没有源可用 如果我没有使用断点没有任何事情发生,程序正在运行,但我没有得到任何错误,但它也无法正常工作。
我该怎么办?我不明白我应该把它放在那里而不是“我的节点”
答案 0 :(得分:2)