php - 在 Crontab 中获取包含 jQuery 帖子的网页

标签 php jquery python linux curl

我想做一个像普通浏览器一样简单地“访问”网页的 cronjob。在这个网页上我有一个脚本:

<script>
var x = 0;

while(x<10) {

     setTimeout(
     function() {

        if ($(".instashow-gallery-media-image img")[0]){ // If image exists

        var html = $('#instaWrapper').html();
        $('#content').val(html);

        x = 10; // Breaks the loop

        setTimeout(
        function() {
           $('#contentSubmit').submit();
           }, 2000); // Wait 2 seconds, then submit             

        } else {
          // Couldn't find the image, trying again
        }

        }, 1000);

        x++;
     }
 </script>

如果我在终端中执行 curl,javascript 将不会运行,并且永远不会发布。 是否有模拟 Chrome、Safari 等实际访问的“curl”?或者我可以编写一个 Php 或 Python 脚本,然后添加到我的 crontab 中吗?

谢谢!

最佳答案

您可以像这样在 PHP 中使用 CURL:

<?php
$ch = curl_init('http://www.google.com/');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_USERAGENT, 'Enter your browser agent string here');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status == 200) {
    // $output contains URLs data, if needed
}

如果您将 CURLOPT_USERAGENT 设置为您想要的用户代理字符串,那么该请求将显示为来自该浏览器。

我想这取决于你想对数据做什么,你是只想 ping URL,还是想实际显示网站,就好像浏览器正在访问它一样。

关于php - 在 Crontab 中获取包含 jQuery 帖子的网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854247/

相关文章:

php - 查询查找以相同价格出售三种不同啤酒的所有酒吧

PHP Preg-替换多于一个下划线

Jquery .on ("click") 第二次不起作用

python - 使用 Flask-WTForms 字段描述渲染 html 标题属性

javascript - 解析获取查询字符串并使用值来更改复选框状态

javascript - FullPage.js 触摸滚动固定元素

Javascript 对 URL 进行 Post 或 Get 调用并返回页面上的文本

python - excel for python 中动态值字符串的富文本

python - Pandas:对给定列求和 DataFrame 行

php - 查询结果存入变量