使用jQuery和Ajax网站刮 [英] Website scraping using jquery and ajax

查看:159
本文介绍了使用jQuery和Ajax网站刮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够操纵一个给定的URL的HTML。像HTML刮。我知道这是可以做到使用卷曲或某些刮library.But我想知道是否有可能使用jQuery用ajax做一个GET请求的URL和检索URL的HTML,并运行jQuery的code对返回的HTML?

I want to be able to manipulate the html of a given url. Something like html scraping. I know this can be done using curl or some scraping library.But i would like to know if it is possible to use jquery to make a get request to the url using ajax and retrieve the html of the url, and run jquery code on the html returned ?

感谢您

推荐答案

我想指出的是,在有些情况下是完全可以接受的使用jQuery跨域刮屏幕。 Windows边栏小工具运行在本地计算机区域,允许跨域脚本。

I would like to point out that there are situations where it is perfectly acceptable to use jQuery to scrape screens across domains. Windows Sidebar gadgets run in a 'Local Machine Zone' that allows cross domain scripting.

和jQuery也必须选择适用于retreived HTML内容的能力。你只需要一个空间后,选择添加到load()方法的URL参数。

And jQuery does have the ability to apply selectors to retreived html content. You just need to add the selector to a load() method's url parameter after a space.

下面检查的例子小工具code本页面每隔一小时,并报告的页面访问量总数。

The example gadget code below checks this page every hour and reports the total number of page views.

<html>
<head>
    <script type="text/javascript" src="jquery.min.js"></script>
    <style>
        body { 
            height: 120px;
            width: 130px;
            background-color: white;
        };
    </style>
</head>

<body>
Question Viewed:
<div id="data"></div>

<script type="text/javascript">

    var url = "http://stackoverflow.com/questions/1936495/website-scraping-using-jquery-and-ajax"

    updateGadget();

    inervalID = setInterval("updateGadget();", 60 * 1000);

    function updateGadget(){

        $(document).ready(function(){
            $("#data").load(url + " .label-value:contains('times')");
        });

    }

</script>

</body>
</html>

这篇关于使用jQuery和Ajax网站刮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆