php从链接下载网页的所有图像
当我使用curl或file_get_内容下载html时,我不会得到只需在chrome上按F12,然后转到网络选项卡。php从链接下载网页的所有图像,php,curl,Php,Curl,当我使用curl或file_get_内容下载html时,我不会得到只需在chrome上按F12,然后转到网络选项卡。 找到tumbex的api url,然后将其与请求头一起复制。 如果完成,您可以使用该url(api url)的curl来获得响应。 这是我的密码 <?php $page = 1; //change number of page here $url = "https://api.1.tumbex.com/api/tumblr/posts?tumblr=memes&a
找到tumbex的api url,然后将其与请求头一起复制。
如果完成,您可以使用该url(api url)的curl来获得响应。
这是我的密码
<?php
$page = 1; //change number of page here
$url = "https://api.1.tumbex.com/api/tumblr/posts?tumblr=memes&type=posts&page=$page&tag=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'Accept: */*',
'Authorization: Bearer 0fae0f237b33e781a6884295b39c6e903484ef1ee3190bd51f07dd9881bdccbd',
'content-type: application/json; charset=UTF-8',
'Referer: https://www.tumbex.com/',
'Accept: application/json, text/plain, */*',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36',
'x-csrf-token: MVMyb2hLTWtQdEJEYjJ0SER1dEwvZz09',
'x-requested-with: XMLHttpRequest'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$res = curl_exec($ch); //result is json
$json = json_decode($res, true);
$edan = $json['response']['posts'];
for($i=0; $i<count($edan); $i++){
$get_post = $edan[$i];
$type = $get_post['detected_type']; //get type
//$get_photo = $get_post['blocks'][0]['content'][0]['hd']; -> get image url
//$get_video = $get_post['blocks'][0]['content'][0]['media']['url']; -> get video url
//$get_text1 = $get_post['blocks'][0]['content'][0]['text']; -> get text 1
//$get_text2 = $get_post['blocks'][0]['content'][1]['text']; -> get text 2
if($type == 'photo'){
$get_photo = $get_post['blocks'][0]['content'][0]['hd'];
echo "<img src='".$get_photo."' height='120' width='160'><br>";
}
}
该页面似乎正在运行JavaScript来更新UI。检查浏览器调试工具中的“网络”选项卡以查看它发出的所有请求。通过逆向工程来获取数据,这比获取初始HTML要复杂得多。要解决此问题,您可能需要阅读并理解以下内容:。谢谢您的回答。但是我试过了,它不起作用$res是空的,您是如何到达该链接的?@Theppep再次读到,“您必须知道,如果结果为空,则承载令牌和x-csrf-token总是在变化,这意味着承载令牌和x-csrf-token已过期,但是,您可以手动解决该问题,或者使用其他curl自动获取承载令牌和x-csrf-token…”对不起,我是一个noob。承载令牌和x-csrf-token存储在哪里?而且我还不知道你是怎么找到链接的
$html = get_dataa('https://www.tumbex.com/memes.tumblr/posts?page=2');
echo($html);
function get_dataa($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
<?php
$page = 1; //change number of page here
$url = "https://api.1.tumbex.com/api/tumblr/posts?tumblr=memes&type=posts&page=$page&tag=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'Accept: */*',
'Authorization: Bearer 0fae0f237b33e781a6884295b39c6e903484ef1ee3190bd51f07dd9881bdccbd',
'content-type: application/json; charset=UTF-8',
'Referer: https://www.tumbex.com/',
'Accept: application/json, text/plain, */*',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36',
'x-csrf-token: MVMyb2hLTWtQdEJEYjJ0SER1dEwvZz09',
'x-requested-with: XMLHttpRequest'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$res = curl_exec($ch); //result is json
$json = json_decode($res, true);
$edan = $json['response']['posts'];
for($i=0; $i<count($edan); $i++){
$get_post = $edan[$i];
$type = $get_post['detected_type']; //get type
//$get_photo = $get_post['blocks'][0]['content'][0]['hd']; -> get image url
//$get_video = $get_post['blocks'][0]['content'][0]['media']['url']; -> get video url
//$get_text1 = $get_post['blocks'][0]['content'][0]['text']; -> get text 1
//$get_text2 = $get_post['blocks'][0]['content'][1]['text']; -> get text 2
if($type == 'photo'){
$get_photo = $get_post['blocks'][0]['content'][0]['hd'];
echo "<img src='".$get_photo."' height='120' width='160'><br>";
}
}