Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从动态网站获取数据_C#_Asp.net_Angularjs_Parsing_Web Crawler - Fatal编程技术网

C# 从动态网站获取数据

C# 从动态网站获取数据,c#,asp.net,angularjs,parsing,web-crawler,C#,Asp.net,Angularjs,Parsing,Web Crawler,我们有一个旧的windows窗体应用程序,其代码类似于 using System.Net; using System.IO; using System.Windows.Forms; string result = null; string url = "http://www.despegar.cl/shop/flights/results/oneway/ANF/SCL/2016-03-30/1/0/0?from=SB"; WebResponse response = null; StreamR

我们有一个旧的windows窗体应用程序,其代码类似于

using System.Net;
using System.IO;
using System.Windows.Forms;

string result = null;
string url = "http://www.despegar.cl/shop/flights/results/oneway/ANF/SCL/2016-03-30/1/0/0?from=SB";
WebResponse response = null;
StreamReader reader = null;

try
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "GET";
    response = request.GetResponse();
    reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    result = reader.ReadToEnd();
}
catch (Exception ex)
{
    // handle error
    MessageBox.Show(ex.Message);
}
finally
{
    if (reader != null)
        reader.Close();
    if (response != null)
        response.Close();
}
从despegar cl这样的外部网站获取源代码,然后获取航班起飞时间表的数据。 问题在于使用AngularJS或类似框架的页面在运行时替换了这些字段。获得的源代码类似于

<span class="hour">{{data.departure.hour.formatted}}</span>
{{数据.出发.小时.格式化}
当我们想要被发现的时候

<span class="hour">09:05</span>
09:05

如何使用动态字段更新获取数据?

如果不运行Javascript处理视图,使用Angular或其他Javascript框架构建的网页将基本上无法使用。你最好的选择是运行一个无头浏览器,并删除生成的HTML


根据服务器的不同,您可以请求预渲染版本。一些有角度的网站这样做是为了搜索引擎的目的,因为搜索引擎爬虫也不运行Javascript,并且面临与现在相同的问题。您必须检查所查询的任何服务,以确定这是否是一个选项。

您始终可以打开网络查看器,查看它是否从特定端点提取数据,您可能能够将客户端设置为到达端点。。后台可能是json流或xml流。不久前,我不得不这样做,并找到了一个隐藏的api等价物,我可以询问