本帖最后由 jason36900 于 2014-09-06 00:33:15 编辑

解决方案 »

  1.   

    (1)用htmldecode先转码,再用trim
    (2)贴出html代码片段,好提供给你一个正则表达式来过滤
      

  2.   

    第一和第二都可以用正则表达式来处理
    处理转义字符比较简单,HTML 就那么几种转义字符,可以使用正则表达式一次性进行替换。获取 img 的也可以使用正则表达式来处理,例如,底下是一个简单的示例打印出页面中的图片。
            static void Main(string[] args)
            {
                HttpWebRequest request = HttpWebRequest.CreateHttp("http://www.baidu.com");
                using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
                {
                    string line = default(string);
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[<|\\s]+img src=\"([^\"]+)\"");                while ((line = reader.ReadLine()) != null)
                    {
                        System.Console.WriteLine(line);                    if (regex.IsMatch(line))
                        {
                            foreach (System.Text.RegularExpressions.Match match in regex.Matches(line))
                            {
                                System.Console.WriteLine(match.Groups[1].Value);
                            }
                        }
                    }
                }            System.Console.ReadKey();
            }
      

  3.   

    <div id="InnerTopicLeft">
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><img src="images/InnerTopicIcon001.jpg" alt="標題" border="0" /></td>
    <td id="InnerTopic">LINE跑跑薑餅人愛心接力跑!</td>
    </tr>
    </table>
    </div>
    <div id="InnerTopicRight">大概是這個片段
    要抓到<td><img  裡面的照片
    但問題在於 我一次想要抓取的文章有9筆
    但不是每筆都有照片
    且並不一定都是放在div 跟td裡面 (有的是<p>裡)
    所以想請問能不能鎖定抓到img裡面的圖就好
    而不是固定抓到td呢?
    請大哥賜教