我想从html响应下面得到2269。我用
<td>XYZ Market Services \(Sydney\)</td>(?s).*name="addCompany" value="(.+?)"
使用$ 1 $模板和匹配编号1的正则表达式,但它返回2271.有人请帮我创建一个正则表达式以获得值2269。
<tr>
<td>XYZ Market Services (Sydney)</td>
<td class="center">
<form action="/FormBuilder/pages/Folders/add.aspx?group=1424sfksdfsdgdsf243-3Q-w&ajax=true" method="post">
<input name="addCompany" value="2269" type="hidden" /><input class="XYZLookAlike" type="button" onclick="fnload(this)" value="Add" />
</form>
</td>
</tr>
<tr>
<td>XYZ Market Services (Melbourne)</td>
<td class="center">
<form action="/FormBuilder/pages/Folders/add.aspx?group=1424sfksdfsdgdsf243-3Q-w&ajax=true" method="post">
<input name="addCompany" value="2271" type="hidden" /><input class="XYZLookAlike" type="button" onclick="fnload(this)" value="Add" />
</form>
</td>
</tr>
谢谢...
答案 0 :(得分:1)
Don't use regular expressions to parse HTML,有更好的选择。
例如,您可以使用允许对响应执行任意XPath Extractor的XPath queries,以下是为 public class UIIssueVM : ViewModels.Issue.IssueVM, INotifyPropertyChanged
{
public UIIssueVM()
{
Id = 0;
Title = "";
Description = "";
Created = DateTime.Now;
Edited = DateTime.Now;
}
public UIIssueVM(bool bIsNew)
{
IsNew = true;
Id = 0;
Title = "";
Description = "";
CreatedBy = App.Client.GetCurrentUsername();
Created = DateTime.Now;
Edited = DateTime.Now;
}
public UIIssueVM(ViewModels.Issue.IssueVM issue)
{
LocationId = issue.LocationId;
Id = issue.Id;
Title = issue.Title;
Description = issue.Description;
Longitude = issue.Longitude;
Latitude = issue.Latitude;
Status = issue.Status;
Severity = issue.Severity;
Created = issue.Created;
Edited = issue.Edited;
CreatedBy = issue.CreatedBy;
}
public ViewModels.Issue.NewIssueVM CreateNewIssueVM()
{
ViewModels.Issue.NewIssueVM issue = new ViewModels.Issue.NewIssueVM();
issue.LocationId = LocationId;
issue.Title = Title;
issue.Description = Description;
issue.Longitude = Longitude;
issue.Latitude = Latitude;
issue.Status = Status;
issue.Severity = Severity;
return issue;
}
public ViewModels.Issue.IssueVM CreateUpdatedIssueVM()
{
ViewModels.Issue.IssueVM issue = new ViewModels.Issue.IssueVM();
issue.Id = Id;
issue.LocationId = LocationId;
issue.Title = Title;
issue.Description = Description;
issue.Longitude = Longitude;
issue.Latitude = Latitude;
issue.Status = Status;
issue.Severity = Severity;
issue.CreatedBy = issue.CreatedBy;
return issue;
}
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
// System.Diagnostics.Debug.WriteLine("Update!"); //ok
if (PropertyChanged != null)
{
//PropertyChanged is always null and shouldn't.
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public bool Changed
{
get
{
return this.IssueChanged;
}
set
{
IssueChanged = value;
NotifyPropertyChanged();
}
}
public string TitleEx
{
get
{
return this.Title;
}
set
{
if (this.Title != value)
{
this.Title = value;
NotifyPropertyChanged();
Changed = true;
}
}
}
public string DescriptionEx
{
get
{
return this.Description;
}
set
{
if (this.Description != value)
{
this.Description = value;
NotifyPropertyChanged();
Changed = true;
}
}
}
输入提取value
属性的示例,其中列文本为{ {1}}
addCompany
演示:
答案 1 :(得分:1)
要解析HTML,在可维护性/易用性/性能方面,最好的提取器是CSS/JQuery extractor:
关于提取器的性能,请参阅此内容: