C# HAP“System.Net.WebException:无法解析远程名称”例外
您好,我正在使用此代码从 eBay 获取一些数据。
string url = textBox1.Text;
get_all_link(url);
private void get_all_link(string url)
{
var webGet = new HtmlWeb();
try
{
var document = webGet.Load(url);
MessageBox.Show(url);
var metaTags = document.DocumentNode.SelectNodes("//div[@class='ttl']/a");
if (metaTags != null)
{
foreach (var tag in metaTags)
{
string link = tag.Attributes["href"].Value;
links.Add(link);
}
}
var next = document.DocumentNode.SelectNodes("//td[@class='botpg-next']/a");
if (next != null)
{
string link = "http://www.ebay.com" + next;
get_all_link(link);
}
else return;
}
catch (Exception f)
{
MessageBox.Show(f.ToString());
TextWriter tw = new StreamWriter("data.txt");
tw.WriteLine(f.ToString());
tw.Close();
}
}
System.Net.WebException:无法解析远程名称:'www.ebay.comhtmlagilitypack.htmlnodecollection' 在 System.Net.HttpWebRequest.GetResponse() 在 C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs 中的 HtmlAgilityPack.HtmlWeb.Get(Uri uri、字符串方法、字符串路径、HtmlDocument doc、IWebProxy 代理、ICredentials 信用):第 1446 行 在 C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs 中的 HtmlAgilityPack.HtmlWeb.LoadUrl(Uri uri、字符串方法、WebProxy 代理、NetworkCredential 凭证):第 1563 行 在 C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs 中的 HtmlAgilityPack.HtmlWeb.Load(String url, String method) 处:第 1152 行 在 C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs 中的 HtmlAgilityPack.HtmlWeb.Load(String url) 处:第 1107 行 在 C:\Documents and Settings\maruf\My Documents\Visual Studio 2008\Projects\BackgroundWorker\BackgroundWorker\Form1.cs 中的 BackgroundWorker.Form1.get_all_link(String url):第 86 行
我在这里检查了一些帖子。但无法解决这个问题。我该如何解决这个问题?有什么建议吗?提前致谢 :)
Hi I am using this code to get some data from ebay .
string url = textBox1.Text;
get_all_link(url);
private void get_all_link(string url)
{
var webGet = new HtmlWeb();
try
{
var document = webGet.Load(url);
MessageBox.Show(url);
var metaTags = document.DocumentNode.SelectNodes("//div[@class='ttl']/a");
if (metaTags != null)
{
foreach (var tag in metaTags)
{
string link = tag.Attributes["href"].Value;
links.Add(link);
}
}
var next = document.DocumentNode.SelectNodes("//td[@class='botpg-next']/a");
if (next != null)
{
string link = "http://www.ebay.com" + next;
get_all_link(link);
}
else return;
}
catch (Exception f)
{
MessageBox.Show(f.ToString());
TextWriter tw = new StreamWriter("data.txt");
tw.WriteLine(f.ToString());
tw.Close();
}
}
this is the link to be parsed : http://www.ebay.com/sch/i.html?_nkw=gruen+-sara+-quartz+-embassy+-bob+-robert+-elephants+-adidas&_sacat=0&LH_Auction=1&_dmpt=Wristwatches&_odkw=gruen+-sara+-quartz+-embassy+-bob+-robert+-elephants+-adidas&_osacat=1&_trksid=p3286.c0.m270.l1313 and it's writing the following exception in file
System.Net.WebException: The remote name could not be resolved: 'www.ebay.comhtmlagilitypack.htmlnodecollection' at System.Net.HttpWebRequest.GetResponse() at HtmlAgilityPack.HtmlWeb.Get(Uri uri, String method, String path, HtmlDocument doc, IWebProxy proxy, ICredentials creds) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1446 at HtmlAgilityPack.HtmlWeb.LoadUrl(Uri uri, String method, WebProxy proxy, NetworkCredential creds) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1563 at HtmlAgilityPack.HtmlWeb.Load(String url, String method) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1152 at HtmlAgilityPack.HtmlWeb.Load(String url) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1107 at BackgroundWorker.Form1.get_all_link(String url) in C:\Documents and Settings\maruf\My Documents\Visual Studio 2008\Projects\BackgroundWorker\BackgroundWorker\Form1.cs:line 86
I have checked some post here . but couldn't solve this problem. How can I solve this ?? Any suggestion ?? Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
返回一个
node
对象,而不是一个string
。您需要使用该对象的属性之一,可能是诸如href
或link
之类的属性,并相应地使用它。Returns a
node
object and not astring
. You need to use one of the properties of this object, likely to be somethign likehref
orlink
and use this accordingly.您没有在 FQDN 和路径之间添加斜杠,而是向字符串添加
HtmlAgilityPack.HtmlNodeCollection
,这是行不通的。You're not adding a slash between the FQDN and the path, and you are adding a
HtmlAgilityPack.HtmlNodeCollection
to a string, which won't work.