问题描述
我正在开发一个Windows窗体应用程序,它与网站交互。
I am developing a Windows Forms application which is interacting with a web site.
使用 web浏览器
控制我控制的网站,我可以使用通过标签迭代:
Using a WebBrowser
control I am controlling the web site and I can iterate through the tags using:
HtmlDocument webDoc1 = this.webBrowser1.Document;
HtmlElementCollection aTags = webDoc1.GetElementsByTagName("a");
现在,我想从哪个低于标签的特定文本:
Now, I want to get a particular text from the tag which is below:
<一href=\"issue?status=-1,1,2,3,4,5,6,7&@sort=-activity&@search_text=&@dispname=Show Assigned&@filter=status,assignedto&@group=priority&@columns=id,activity,title,creator,status&assignedto=244&@pagesize=50&@startwith=0\">Show分配< / A>< BR>
喜欢这里我想这是上面的标签等于 assignedto
数244,并将其保存为进一步使用的变量。
Like here I want to get the number 244 which is equal to assignedto
in above tag and save it into a variable for further use.
我怎样才能做到这一点?
How can I do this?
推荐答案
您可以尝试通过拆分一个字符串';'值,然后每串用'='是这样的:
You can try splitting a string by ';' values, and then each string by '=' like this:
string aTag = ...;
foreach(var splitted in aTag.Split(';'))
{
if(splitted.Contains("="))
{
var leftSide = splitted.Split('=')[0];
var rightSide = splitted.Split('=')[1];
if(leftSide == "assignedto")
{
MessageBox.Show(rightSide); //It should be 244
//Or...
int num = int.Parse(rightSide);
}
}
}
另一种选择是使用的正则表达式,你可以在这里进行测试:。和正则表达式一些更多的信息:的
Other option is to use Regexes, which you can test here: www.regextester.com. And some more info on regexes: http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx
希望它帮助!
这篇关于解析HTML - 如何从一个标签的号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!