当前位置:网站首页>PHP uses curl to download Excel files after logging in to the website
PHP uses curl to download Excel files after logging in to the website
2022-06-28 23:25:00 【supramolecular】
PHP utilize curl To realize the login , preservation cookie To the file
<?php
header("Content-Type:text/html;charset=utf-8");
$curl = curl_init();
//$cookie_jar = tempnam('./tmp','cookie'); //tempnam-- Create a file with a unique filename
curl_setopt($curl, CURLOPT_URL,'https://www.baidu.com');// Write the login processing interface here
curl_setopt($curl, CURLOPT_POST, 1); //post Submit data
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , 0); //post Submit data
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST , 0); //post Submit data
$request = 'name=****&password=*****';
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);// To transfer data
curl_setopt($curl, CURLOPT_COOKIEJAR, "a.txt");// Bring back cookie The information is kept in $cookie_jar In file
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);// Set whether the returned data is automatically displayed
curl_setopt($curl, CURLOPT_HEADER, false);// Set whether to display header information
curl_setopt($curl, CURLOPT_NOBODY, false);// Set whether to output page content
curl_exec($curl);// Return results
if(curl_exec($curl) === false)
{
echo 'Curl error: ' . curl_error($curl);
}
else
{
echo ' The operation is completed without any errors ';
}
curl_close($curl); // close */PHP utilize cookie File implementation requires login get download EXcel
<?php
header("Content-Type:text/html;charset=utf-8");
$cookie_jar = dirname(__FILE__) . "/a.txt"; // The saved cookie Information file path
$url = "https://www.baidu.com/filepath";
$arr = curl_get($url, $cookie_jar);
/**
*curl post request
*/
function curl_post($url, $data, $cookie_jar)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return = curl_exec($ch);
curl_close($ch);
}
/**
*curl get request
*/
function curl_get($url, $cookie_jar)
{
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, $url);// Which page to get information from after logging in
curl_setopt($curl2, CURLOPT_HEADER, false);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER , 0); //post Submit data
curl_setopt($curl2, CURLOPT_SSL_VERIFYHOST , 0); //post Submit data
curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);
$content = curl_exec($curl2);
file_put_contents("a.xlsx", $content);
if(curl_exec($curl2) === false)
{
echo 'Curl error: ' . curl_error($curl2);
}
else
{
echo ' The operation is completed without any errors ';
}
curl_close($curl2);
}
边栏推荐
- 2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fm
- frameworks/base/core/res/res/values/symbols.xml:3915: error: no definition for declared symbol解决办法
- Oil monkey script learning
- Langage C - analyse des mots
- Machine learning 4-dimension reduction technology
- 2022年PMP项目管理考试敏捷知识点(4)
- 设计电商秒杀系统
- YuMinHong set up two funds funded by his hometown
- C language - word analysis
- Do you know all the wonderful functions of the vlookup function?
猜你喜欢

Behaviortree in ros2

机器学习4-降维技术

再次上榜!知道创宇入选2022中国网安产业竞争力50强
![[state machine design] Moore, Mealy state machine, three-stage, two-stage and one-stage state machine writing specification](/img/48/e29f34aff7cc437bfb574591d54e3d.png)
[state machine design] Moore, Mealy state machine, three-stage, two-stage and one-stage state machine writing specification

ERROR 1067 (42000): Invalid default value for ‘end_ time‘ Mysql

ROS2中的行为树 BehaviorTree

Interviewer: what is the internal implementation of strings in redis?

Use conditional breakpoints in vscode (based on GDB)

移动端异构运算技术 - GPU OpenCL 编程(基础篇)

Machine learning 6-decision tree
随机推荐
【Word 教程系列第 1 篇】如何去除 Word 表格中的箭头
mysql-5.7.30-winx64免安装版下载安装教程
TDD案例实战
Yyds dry inventory solution sword finger offer: maximum sum of continuous subarrays (II)
C語言-單詞分析解析
Cs5463 code module analysis (including download link)
第四章 存储器管理练习
[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word
Use conditional breakpoints in vscode (based on GDB)
[chapter 71 of the flutter problem series] mutual conversion between uint8list and image in flutter
One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards
Design e-commerce seckill system
Advice to friends
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
【OpenCV】—线性滤波:方框滤波、均值滤波、高斯滤波
Mysql-5.7.30-winx64 installation free download and installation tutorial
ERROR 1067 (42000): Invalid default value for ‘end_ time‘ Mysql
Insomnia last night
Class extension and optional type extension of dart
pymysql.Error 获取错误码与具体错误信息