请问一下,用javascript可以通过document.getElementById得到本网页的任何一个元素的信息,可是我想得到别的网页(比如www.baidu.com中的title的innerHTML)上的信息,然后显示在我的页面上,如何做啊?

解决方案 »

  1.   

    得不到,如果你想得到框架<frame,上面的元素,
    在父层通过document.framename.document.getelementById("");在子层得到父层用top.document.getElementById("");
      

  2.   

    通过httpwebrequest请求,抓取网站的内容,然后通过正则匹配抓取出title中的内容
      

  3.   

    给你写个代码  string str =string.Empty;
      WebRequest Wrq = WebRequest.Create("http://www.baidu.com");
                    WebResponse Wrs = Wrq.GetResponse();
                    Stream strm = Wrs.GetResponseStream();
                    StreamReader sr = new StreamReader(strm, System.Text.Encoding.GetEncoding("UTF-8"));
                    string allstrm;
                    allstrm = sr.ReadToEnd();
                    string strPattern = @"正则表达式";
                    MatchCollection Matches = Regex.Matches(allstrm, strPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                    foreach (Match NextMatch in Matches)
                    {
                        str = NextMatch.Groups[0].Value.ToString().Trim();
                    }就是这样
      

  4.   

    只用JS不可能,
    即使你用iframe,你的访问会被拒绝
      

  5.   

    多谢大家了,我又有了个新的思路,通过
    string url = this.TextBox2.Text;
            if (url.Length == 0)
            {
                url = @"http:\\www.baidu.com";
            }
            WebClient myclient = new WebClient();
            byte[] mybytes = myclient.DownloadData(url);
            this.TextBox1.Text = Encoding.Default.GetString(mybytes);
            myclient.Dispose();
    进而分析这个字符串就ok了