【发布时间】:2020-03-22 14:37:47
【问题描述】:
我希望能够得到“The Merinda Flat Sandal In Silver”,这是一种形式,这是代码 <p class="product_note">The Merinda Flat Sandal In Silver</p>
我想将它复制到下面代码中的字符串,但要获取文本而不是值
string id = "https://www.factory54.co.il/products/Logo-canvas-sneakers-in-White-No-167";
Console.WriteLine(HtmlAgi(id));
}
public static string HtmlAgi(string url)
{
var Webget = new HtmlWeb();
var doc = Webget.Load(url);
HtmlNode ourNode = doc.DocumentNode.SelectSingleNode(("//form[@class]"));
if (ourNode != null)
{
return ourNode.GetAttributeValue("class", "");
}
else
{
return "not fount";
}
}```
```<div class="produtshow clearfix">
<h1 id="manufacturer_header"><a href="https://www.factory54.co.il/designers/stuart-weitzman" title="Stuart Weitzman">Stuart Weitzman</a> <p class="product_note">The Merinda Flat Sandal In Silver</p>
</h1>
</div>```
And here is where the text is in the html file (this is located in a form)
【问题讨论】:
-
这需要更多解释。这个 HTML 是从哪里来的。你正在运行什么样的 C# 程序?
-
这只是一个html表单的例子。我正在运行 HttpRequest 但在此之前我想知道这就是为什么我需要这个操作我的意思是程序获取 URL 并复制操作的值
-
还是不清楚。让我换一种说法:为什么不能直接将 HTML 读入 C# 程序并在其中搜索所需的文本?
-
听起来不错,我该怎么做|?
标签: c# html httprequest