Heim  >  Artikel  >  Backend-Entwicklung  >  javascript - php爬虫ajax请求地址怎么获取?

javascript - php爬虫ajax请求地址怎么获取?

WBOY
WBOYOriginal
2016-06-06 20:28:011586Durchsuche

用php爬虫抓取网页,网页上有个信息需要登录后才显示在页面中,是一个ajax请求的信息。按F12找到了这个ajax请求地址,javascript生成的,那么,如何获取这个地址呢?

补充:
ajax请求的jquery代码:

<code>$(document).ready(function(){
    var id="100";
    var tsTimeStamp= new Date().getTime();
    $.get("http://www.xxxx.com/extra/ajax_contact.php", { "id": id,"time":tsTimeStamp,"act":"locations_contact"},
        function (data,textStatus)
         {            
            $("#locations_contact").html(data);
         }
    );
})
</code>

按F12在那个框里面显示的ajax请求地址:ajax_contact.php?id=100&time=1442484035051&act=locations_contact
把上面这个地址在新窗口打开显示的完整地址:http://www.xxxx.com/extra/ajax_contact.php?id=100&time=1442484035051&act=locations_contact

每个页面id不一样,怎么把这个地址取到?

回复内容:

用php爬虫抓取网页,网页上有个信息需要登录后才显示在页面中,是一个ajax请求的信息。按F12找到了这个ajax请求地址,javascript生成的,那么,如何获取这个地址呢?

补充:
ajax请求的jquery代码:

<code>$(document).ready(function(){
    var id="100";
    var tsTimeStamp= new Date().getTime();
    $.get("http://www.xxxx.com/extra/ajax_contact.php", { "id": id,"time":tsTimeStamp,"act":"locations_contact"},
        function (data,textStatus)
         {            
            $("#locations_contact").html(data);
         }
    );
})
</code>

按F12在那个框里面显示的ajax请求地址:ajax_contact.php?id=100&time=1442484035051&act=locations_contact
把上面这个地址在新窗口打开显示的完整地址:http://www.xxxx.com/extra/ajax_contact.php?id=100&time=1442484035051&act=locations_contact

每个页面id不一样,怎么把这个地址取到?

分析js, 找js是怎么拼这个地址的, 用的哪些变量, 这个变量的值又是哪里来的,然后自己组装.


<code class="php"><?php $html = '';//这里为抓到的HTML内容

preg_match('/var id="(\d+)";/', $html, $result);//匹配出来 id的值,

//接下来你就可以用取到的id(保存在变量 $result 中), 接到你抓到的那个URL中发请求了.
</code></code>

javascript - php爬虫ajax请求地址怎么获取?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn