Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php下载纳斯达克公司名单_Php - Fatal编程技术网

用php下载纳斯达克公司名单

用php下载纳斯达克公司名单,php,Php,使用浏览器在纳斯达克下载公司列表时,一切正常 网址: 但是,当一段时间后尝试使用PHP执行相同操作时,将出现错误“无法打开流HTTP” 我在同一主题上发现了另一个问题: 虽然不知道如何在PHP中实现这一点。尝试使用具有不同标题集的文件\u get\u内容和curl,但无法使其正常工作。使用与类似问题中相同的标题以及我的浏览器在成功下载时使用的标题进行测试 谁能给我一个例子,如何使这在PHP的工作?标题中有问题吗?您可以使用shell\u exec或普通的PHP curl库来使用curl请求。我对

使用浏览器在纳斯达克下载公司列表时,一切正常

网址:

但是,当一段时间后尝试使用PHP执行相同操作时,将出现错误“无法打开流HTTP”

我在同一主题上发现了另一个问题:

虽然不知道如何在PHP中实现这一点。尝试使用具有不同标题集的文件\u get\u内容和curl,但无法使其正常工作。使用与类似问题中相同的标题以及我的浏览器在成功下载时使用的标题进行测试


谁能给我一个例子,如何使这在PHP的工作?标题中有问题吗?

您可以使用shell\u exec或普通的PHP curl库来使用curl请求。我对shell_exec很满意,这就是为什么以这种方式显示代码

$url = 'https://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download';
$output = shell_exec('curl -J -O -L -k -s "'. $url .'"');
与curl一起使用的选项如下所示,有关这些选项的更多详细信息,请执行
man curl

-J, --remote-header-name
          (HTTP) This option tells the -O, --remote-name option to use the server-specified Content-Disposition filename instead of extracting a filename from the URL.

          There's no attempt to decode %-sequences (yet) in the provided file name, so this option may provide you with rather unexpected file names.
-k, --insecure
              (SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bun‐
              dle installed by default. This makes all connections considered "insecure" fail unless -k, --insecure is used.

              See this online resource for further details: http://curl.haxx.se/docs/sslcerts.html
-O, --remote-name
              Write output to a local file named like the remote file we get. (Only the file part of the remote file is used, the path is cut off.)

              The remote file name to use for saving is extracted from the given URL, nothing else.

              Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure  you  change  current  working  directory
              before you invoke curl with the -O, --remote-name flag!

              There is no URL decoding done on the file name. If it has %20 or other URL encoded parts of the name, they will end up as-is as file name.

              You may use this option as many times as the number of URLs you have.
-L, --location
              (HTTP/HTTPS)  If  the  server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make
-s, --silent
              Silent or quiet mode. Don't show progress meter or error messages.  Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you
              redirect it.

这是我的最新版本:header('Host:www.nasdaq.com');标题('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8');标题('AcceptEncoding:gzip,deflate');标头(“升级-不安全-请求:1”);标题('User-Agent:Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/69.0.3497.100 Safari/537.36')$cont=文件获取内容($url)
file\u get\u get\u contents()
将忽略您的标题。您应该在cURL参数中使用并定义您的头,命令行中的cURL至少返回一些内容,即使没有选项,但仍然不确定为什么PHP中的cURL不起作用。尝试了以下操作,但脚本仍然挂起:$ch=curl_init();$timeout=5;curl_setopt($ch,CURLOPT_URL,$URL);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);curl_setopt($ch,CURLOPT_HTTPHEADER,array('Host:www.nasdaq.com','Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8','AcceptEncoding:gzip,deflate','Upgrade-unsecure-Requests:1','User-Agent:Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/69.0.3497.100 Safari/537.36’);$data=curl\u exec($ch);旋紧($ch)好的。但它可能与curl命令行一起工作。那么,你的目的是否解决了呢?也许是技术上的,但不是我的意思。你认为呢,如果我接受你的回答并提出一个新的问题,我会说得更好:)这取决于你,我不能强迫你。若你们在寻找输出,那个么给出的答案足以满足你们的需要。为了增加知识,需要对上述代码做更多的工作。