【发布时间】:2020-06-24 14:53:25
【问题描述】:
目前我想从 instagram url 获取图像。网址是这个
https://www.instagram.com/p/B_zZCRpB895/media/?size=t
我现在在做什么:
$image = file_get_contents("https://www.instagram.com/p/B_zZCRpB895/media/?size=t");
我在我的 AWS 服务器上运行它,但结果是登录 instagram。
<!DOCTYPE html>\n
<html lang="en" class="no-js not-logged-in client-root">\n
<head>\n
<meta charset="utf-8">\n
<meta http-equiv="X-UA-Compatible" content="IE=edge">\n
\n
<title>\n
Login • Instagram\n
</title>\n
\n
\n
<meta name="robots" content="noimageindex, noarchive">\n
<meta name="apple-mobile-web-app-status-bar-style" content="default">\n
<meta name="mobile-web-app-capable" content="yes">\n
<meta name="theme-color" content="#ffffff">\n
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover">\n
<link rel="manifest" href="/data/manifest.json">\n
......
但是,如果我遇到本地 PC。我可以显示图像代码。有什么方法可以从 url instagram 获取图片代码?
【问题讨论】:
-
你的意思是你的代码可以在你的本地电脑上运行,还是你的意思是你可以在你的电脑上通过浏览器访问链接?
-
我的代码可以在我的本地 PC 上运行。但不同于 AWS 服务器
-
Instagram 可能会阻止来自不使用官方 api 的 aws 服务器的 IP 地址。也许 aws 还会在请求中发送一些不同的标头。 php.net/manual/en/function.file-get-contents.php 此链接中的示例向您展示了如何随请求发送标头。我也从 instagram 上抓取信息而不使用那里的 api,对我来说它工作正常(我将它托管在一家荷兰服务器公司上)