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

WBOY
Release: 2016-06-06 20:28:01
Original
1586 people have browsed it

用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>
Copy after login
Copy after login

按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>
Copy after login
Copy after login

按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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!