我如何绕过Instagram上的bot阻塞来获取包含文件内容的完整页面
我正试图从Instagram(IG)用户页面中获取数据,用作网站的流式提要,但很明显,IG使用了一个机器人拦截器,因此PHP方法不会返回JSON字符串的所有元素 我试图获取的数据如下所示,特别是我如何绕过Instagram上的bot阻塞来获取包含文件内容的完整页面,instagram,file-get-contents,Instagram,File Get Contents,我正试图从Instagram(IG)用户页面中获取数据,用作网站的流式提要,但很明显,IG使用了一个机器人拦截器,因此PHP方法不会返回JSON字符串的所有元素 我试图获取的数据如下所示,特别是“ProfilePage”:[{}]对象,未登录IG时可通过本地浏览器看到该对象 <script type="text/javascript">window._sharedData = { "config": { "csrf_token
“ProfilePage”:[{}]
对象,未登录IG时可通过本地浏览器看到该对象
<script type="text/javascript">window._sharedData = {
"config": {
"csrf_token": "MaYaasysNl6fy19YthOGUNVOXvYitbmO",
"viewer": null,
"viewerId": null
},
"country_code": "US",
"language_code": "en",
"locale": "en_US",
"entry_data": {
"ProfilePage": [{
"logging_page_id": "profilePage_28995773",
"show_suggested_profiles": true,
"show_follow_dialog": false,
"graphql": {
"user": {
//[...more data follows including images and links]
}
}
</script>
我尝试使用cURL
,file\u get\u contents()
,new-DOMDocument()->loadHTMLFile()
获取所有页面源代码,然后对需要的行进行preg\u match
匹配,但这两种方法都无法绕过阻止程序
$ig = file_get_contents($url);
preg_match_all('#shortcode":"(.*)",#i',$ig, $match);
预期收益
文字返回
如何获得所需的数据?我定义了一个解决方案
https://instagram.com/graphql/query/?query_id=17888483320059182&variables={"id":"217723373","first":8,"after":null}
如何从用户名中提取用户id?ig basic profile api返回一个不同的用户id,该id不适用于此graphql api。
Array
(
[0] => CB-W_D2h3Sz
[1] => B65TtGYBH8Z
[2] => B65SNqsha6O
[3] => B62NvlShguS
[4] => B6zwW5CBETr
[5] => B6wbz5nB_dP
[6] => B6wa3rxBOOP
[7] => B6uw9RwBSSd
[8] => B6tg9dIh_XB
[9] => B6tYekYhIe8
[10] => B6pR-pGhvoE
[11] => B6pRhVgBwaZ
)
Array
(
)
https://instagram.com/graphql/query/?query_id=17888483320059182&variables={"id":"217723373","first":8,"after":null}