Joe*_*Joe 15 javascript ajax jquery screen-scraping
我希望能够操纵给定网址的html.像html抓取的东西.我知道这可以使用curl或一些抓取库来完成.但是我想知道是否可以使用jquery使用ajax对url发出get请求并检索url的html,并运行jquery代码HTML返回?
谢谢
我想指出,在某些情况下,使用jQuery跨域扫描屏幕是完全可以接受的.Windows边栏小工具在允许跨域脚本编写的"本地计算机区域"中运行.
并且jQuery确实能够将选择器应用于已检索的html内容.您只需要在空格后将选择器添加到load()方法的url参数.
下面的示例小工具代码每小时检查一次此页面并报告总页面查看次数.
<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>
Run Code Online (Sandbox Code Playgroud)
http://www.nathanm.com/ajax-bypassing-xmlhttprequest-cross-domain-restriction/
唯一的问题是,由于 Internet Explorer 和 FireFox 中的安全性,不允许 XMLHTTPRequest 对象发出跨域、跨协议或跨端口请求。
归档时间: |
|
查看次数: |
27897 次 |
最近记录: |