代码之家  ›  专栏  ›  技术社区  ›  Meyer Denney

正在尝试下载电影列表

c#
  •  0
  • Meyer Denney  · 技术社区  · 13 年前

    我正在尝试从这个网站下载电影标题、日期和长度的列表 http://www.fancast.com/movies 我拥有的代码是:

    // used to build entire input
            StringBuilder sb = new StringBuilder();
    
            // used on each read operation
            byte[] buf = new byte[8192];
    
            // prepare the web page we will be asking for
            HttpWebRequest request = (HttpWebRequest)
                WebRequest.Create("http://www.fancast.com/movies");
    
            // execute the request
            HttpWebResponse response = (HttpWebResponse)
                request.GetResponse();
    
            // we will read data via the response stream
            Stream resStream = response.GetResponseStream();
    
            string tempString = null;
            int count = 0;
    
            do
            {
                // fill the buffer with data
                count = resStream.Read(buf, 0, buf.Length);
    
                // make sure we read some data
                if (count != 0)
                {
                    // translate from bytes to ASCII text
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
    
                    // continue building the string
                    sb.Append(tempString);
                }
            }
            while (count > 0); // any more data to read?
    

    它借用了我在网上找到的一些示例代码。但是,当我查看它下载的内容时,它不包含我要查找的信息。它与网站的“查看源代码”具有相同的信息。它似乎正在打电话给另一个有信息的网站,但我似乎找不到或无法访问它。对于如何获取电影标题、长度和/或日期列表的任何帮助都将不胜感激。谢谢!

    2 回复  |  直到 8 年前
        1
  •  1
  •   Gerardo Grignoli    13 年前

    准确地说,如果您分析该网页的源代码,您将看到电影是从另一个URL加载的。 使用Google Chrome开发人员工具(或任何其他工具,如我真正推荐的“Fiddler2”)来跟踪显示网页时浏览器下载的所有资源。

    我做到了,似乎电影数据库是从以下位置获取的: http://www.fancast.com/movies_free_db.widget

    因此,更改webrequest以指向该URL。

        2
  •  0
  •   riwalk    13 年前

    嗯……你打开了一大罐蠕虫。

    您对结果“…包含与视图源代码相同的信息…”的评论使我认为您不完全理解正在发生的事情的细节。

    我推荐你 HTTP Programming Recipes for C# . 这是我第一次写蜘蛛网时读的书,我认为它会给你一个好的方向推动。