【发布时间】:2014-01-14 19:05:49
【问题描述】:
我是 C# 编码的新手,正在编写一个小程序来从 Mt.Gox 中获取当前比特币值。
这是我目前使用的代码:
namespace BitcoinValueScraper
{
public partial class GetValue : Form
{
public GetValue()
{
InitializeComponent();
}
private void GetValue_Load(object sender, EventArgs e)
{
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.Navigate("www.mtgox.com");
wb.Stop();
wb.Document.GetElementById("lastPrice").SetAttribute("value", textBox1.Text);
}
}
}
这会返回:
“'System.NullReferenceException' 类型的未处理异常 发生在 BitcoinValueScraper.exe 附加信息:对象 引用未设置为对象的实例。”
请帮忙!
【问题讨论】:
-
你在运行编译后的程序没有调试?尝试调试它,这样你就可以看到 NullReferenceException 是从哪一行生成的......
-
可能
wb.Document为空。wb.Document.GetElementById("lastPrice")可能为空。可能textBox1为空。 -
只是一个评论,而不是抓取你可能想要使用他们的 api (en.bitcoin.it/wiki/MtGox/API/HTTP/v1#public_information)。即:data.mtgox.com/api/1/BTCUSD/ticker
标签: c# html screen-scraping getelementbyid scrape