我想知道网页中是否存在特定的产品编号。该页面有一个搜索栏,我确定html类"product-thumb“只有在搜索结果为TRUE时才会出现。所以我想用这个类作为IF语句中TRUE和FALSE的一个例子。我正在使用html agilty pack来完成这个任务,这是我已经有的代码,但它不工作,总是返回FALSE。我谷歌了很多,还找不到合适的解决方案,这就是为什么我在这里留下了不能工作的代码。我有像这样的字符串"url“,因为我会列出许多这样的数字来检查每个产品,准备一个大的循环,但仍然不能使这个测试代码工作。提前谢谢。
string url = "90551";
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
string s = "http://examplewebpage" + url;
doc = web.Load(s);
System.Threading.Thread.Sleep(5000);
if (doc.DocumentNode.HasClass("//*[@class=\"product-thumb") == true)
{
webBrowser1.DocumentText = url + " Yes";
}
else
webBrowser1.DocumentText = url + " No";
https://stackoverflow.com/questions/47670894
复制相似问题