안녕하세요,이 코드를 사용하여 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();
}
}
이것은 파싱 될 링크입니다 : 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 파일에 다음 예외를 작성하고 있습니다.
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
나는 약간의 지점을 여기에서 점검했다. 이 문제를 해결할 수는 없습니다. 어떻게 해결할 수 있을까요 ?? 어떠한 제안 ?? 미리 감사드립니다 :)
var next = document.DocumentNode.SelectNodes("//td[@class='botpg-next']/a");
string
아닌 node
객체를 반환 string
. 이 객체의 속성 중 하나를 사용해야합니다.이 객체는 href
또는 link
와 같은 somethign 일 가능성이 높습니다.
FQDN과 경로 사이에 슬래시를 추가하지 않고 HtmlAgilityPack.HtmlNodeCollection
을 문자열에 추가하면 작동하지 않습니다.