我想做一个像普通浏览器一样简单地“访问”网页的 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/