小编chr*_*s-l的帖子

假装Firefox而不是Phantom.js

当我尝试使用Phantomjs 废弃此站点时,默认情况下,Phantomjs会将以下标头发送到服务器:

"name":"User-Agent",
"value":"Mozilla/5.0 (Unknown; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.1 Safari/534.34"}
Run Code Online (Sandbox Code Playgroud)

我得到了status 405 "Not Allowed"回应.

我在Phantomjs API Reference中读到,为了模仿来自其他浏览器的请求,我应该更改我的User-Agent值.在维基百科上,我找到了我应该用来假装在Ubuntu下的Firefox的价值:

'name': 'User-Agent',
'value': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20120815 Firefox/16.0'
Run Code Online (Sandbox Code Playgroud)

我应该在Phantomjs的哪个部分放置这些属性?我应该在哪里插入它们 - 在page.open里面,或在page.evaluate里面,或者在它的顶部?

user-agent web-scraping http-status-code-405 phantomjs

18
推荐指数
1
解决办法
2万
查看次数

如何使用shell从另一个PHP脚本执行PHP脚本?

我有一个sample.php带有以下内容的php文件:

<?php
echo "Hello World!";
?>
Run Code Online (Sandbox Code Playgroud)

而我想要做的是使用第二个PHP脚本运行这个PHP脚本.

我认为shell_exec可以帮助我,但我不知道它的语法.

顺便说一句,我想用这个文件来执行cpanel.所以我必须执行shell.

有没有办法做到这一点?

php shell shell-exec

9
推荐指数
1
解决办法
9219
查看次数

使用MovieDB通过PHP显示图像海报

我刚开始使用theoviedb JSON api,我现在正在尝试做一些看似简单的事情:显示电影的主要海报.我有一个API密钥,这是我正在使用的代码/响应.

$ca = curl_init();
curl_setopt($ca, CURLOPT_URL, "http://api.themoviedb.org/3/configuration?api_key=MYAPIKEY");
curl_setopt($ca, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ca, CURLOPT_HEADER, FALSE);
curl_setopt($ca, CURLOPT_HTTPHEADER, array("Accept: application/json"));
$response = curl_exec($ca);
curl_close($ca);
//var_dump($response);
$config = json_decode($response, true);
//print_r($config);
//$base = $config['base_url'];
//echo($base);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.themoviedb.org/3/search/movie?query=Monsters+University&api_key=MYAPIKEY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
//print_r($result);
//var_dump($response);
echo("<img src='" . $config[0]['base_url'] . $config[0]['poster_sizes'][2] . $result[0]['poster_path'] . "'/>");
Run Code Online (Sandbox Code Playgroud)

我现在唯一的问题是我试图回显标签来显示海报,但我不确定正确的代码会是什么样的呢?

$responsePHP = json_decode($response);
echo("<img src='" . $responsePHP['poster_path'] . "'/>");
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激! …

php api json themoviedb-api

8
推荐指数
1
解决办法
2万
查看次数

如何在node.js服务器中下载客户端服务器中存储的pdf文件

如何允许客户端使用node.js下载存储在服务器中的pdf文件

请有人帮我解决这个问题.

fs.readFile('temp/xml/user/username.pdf',function(error,data){
    if(error){
       res.json({'status':'error',msg:err});
    }else{
       res.json({'status':'ok',msg:err,data:data});
    }
});
Run Code Online (Sandbox Code Playgroud)

pdf node.js mime-types

5
推荐指数
2
解决办法
1万
查看次数

在REQUEST nodejs中返回json体

我正在使用该request模块向URL发出HTTP GET请求以获取JSON响应.

但是,我的功能不是返回响应的正文.

有人可以帮我这个吗?

这是我的代码:

router.get('/:id', function(req, res) {
  var body= getJson(req.params.id);
  res.send(body);
});
Run Code Online (Sandbox Code Playgroud)

这是我的getJson功能:

function getJson(myid){
  // Set the headers
  var headers = {
   'User-Agent':       'Super Agent/0.0.1',
   'Content-Type':     'application/x-www-form-urlencoded'
  }
  // Configure the request
  var options = {
    url: 'http://www.XXXXXX.com/api/get_product.php',
    method: 'GET',
    headers: headers,
    qs: {'id': myid}
  }

  // Start the request
  request(options, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    return body;
  }
  else
    console.log(error);
  })
}
Run Code Online (Sandbox Code Playgroud)

javascript json httprequest node.js

3
推荐指数
1
解决办法
2万
查看次数

如何在php中提取bz2文件

我已经使用phpmyadmin. 文件被命名final.sql.bz2,然后我将它上传到我的 Live Server。

问题是,如何使用 PHP 代码提取该文件?我试图在谷歌上搜索,但没有得到任何结果。我怎么可能unzip呢?

php extraction bzip2

3
推荐指数
1
解决办法
2718
查看次数

如何写文件原样?

我有一串这样的代码:

<?php
echo "Hello World";
?>
Run Code Online (Sandbox Code Playgroud)

现在,我想把它写成一个php文件就像它一样.我的意思是我想用新的行字符编写这段代码.所以代码以上面的方式存储.那么,我该怎么做呢?

我曾尝试使用文件附加fwrite,但是他们在一个连续的行中编写代码,我想要的是将它分成3行.

  • 在第一行 - <?php
  • 在第二行 - echo "Hello world";
  • 在第三行 - ?>

但我想通过只使用一行代码来完成它,就像下面的那样.

$file = 'people.php';
// The new person to add to the file
$person = "John Smith\n";
// Write the contents to the file, 
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at …
Run Code Online (Sandbox Code Playgroud)

php newline

-6
推荐指数
1
解决办法
424
查看次数