運行一小段代碼說輸入字符串不在正確的合成文件中時,出現錯誤消息。這個問題是從分析這些HTML甲酸異常拋出「輸入字符串的格式不正確」
標記時來了一個
<td class="tdRow1Color" width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td class="plaintextbold">Item Number: 1258</td></tr>
<tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
<tr>
<td class="plaintext" valign="middle"> <img src="../images/0note.gif" border="0" align="absmiddle"> <a class="prodlink" href="writeReview.asp?number=1258"><i><u>Be the first to review this item</u></i></a></td>
</tr>
<tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
<tr><td class="plaintext"><b>RRP £50.00 - Now £39.99</b> </td>
馬克兩個
<tr><td class="tdRow1Color" width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td class="plaintextbold">Item Number: 2525</td></tr>
<tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
<tr>
<td class="plaintext" valign="middle"> <img src="../images/0note.gif" border="0" align="absmiddle"> <a class="prodlink" href="writeReview.asp?number=2525"><i><u>Be the first to review this item</u></i></a></td>
</tr>
<tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
<tr><td class="plaintext">RRP £45 - Now £38
我通過這個正則表達式coverting的RRP價格。
private Regex _originalPriceRegex = new Regex(@"RRP \s(\d+\.?\d+?)");
並通過XPath的
ProductProperties.priceOriginal, new HtmlElementLocator("//td[@class='tdRow1Color']//td[@class='plaintext']//text()[starts-with(., 'RRP')]",
這個問題似乎是在XPath的值傳遞到下面的函數的到達拿起RRP價格。當它返回priceMatch.Groups [1]時拋出異常。值
private string LookForOrignalPrice(HtmlNode node)
{
string text = node.InnerText;
Match priceMatch = _originalPriceRegex.Match(text);
if (priceMatch.Success)
Console.WriteLine("++++++price is " + priceMatch);
return priceMatch.Groups[1].Value;
return null;
}
感謝您提供任何建議。
使用的[HTML解析器(http://htmlagilitypack.codeplex.com/)來解析HTML。另請閱讀:http://stackoverflow.com/a/1732454/932418 –