问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Net;usingSystem.IO;namespaceWindowsApplication2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){System.Net.HttpWebRequestreq;System.Net.HttpWebResponseres;stringurl="http://fanyi.yahoo.com.cn/translate_txt?trtext="+richTextBox2.Text+"&lp=en_zh";req=(System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);res=(System.Net.HttpWebResponse)req.GetResponse();System.IO.StreamReaderstrm=newSystem.IO.StreamReader(res.GetResponseStream(),Encoding.GetEncoding("UTF-8"));stringstr=strm.ReadToEnd();str=str.Substring(str.IndexOf("resultcon")+65,str.IndexOf("div"));richTextBox1.Text=str;}}}结果为:你好,怎么样您</div></div></div></div></form><!--}}}end:translated--><divclass="clr"></div></div><!--}}end:translatearea--><!--{{start:translatepage--><divclass="parea"><divclass="pform"><h2>翻译网页</h2>但是我指向要“你好,怎么样您”这个要怎么弄呢?
解决方案
解决方案二:
分析完整的返回的整体html,用正则匹配你这样肯定不精确的,页面肯定多个div