- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
file_get_contents('https://en.wikipedia.org/wiki/Category:Upcoming_singles');
使用 Chrome 网络浏览器访问同一地址(显示 4 种产品)返回不同的响应(2 种产品)。
经检查,我怀疑这可能与
有关Saved in parser cache key with ... timestamp ...
在返回的 html 中。当我使用 file_get_contents()
关于如何使用 file_get_contents()
获取最新信息有什么想法吗?
谢谢!
最佳答案
假设 file_get_contents
正在发出 http 请求,最好检查指定的用户代理。
我听说使用某些用户代理获取数据时会出现问题。看看this question .
您可以使用流上下文指定其他选项(包括用户代理):
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
查看 file_get_contents docs .
此外,正如 Jack 所说,cURL 是更好的选择。
编辑:
你误会我的意思了。您要添加的是一个不同的用户代理。例如,使用 mozilla firefox 的用户代理可以获得 4 个结果:
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; es-AR; rv:1.9.2.23) Gecko/20110921 Ubuntu/10.10 (maverick) Firefox/3.6.23"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://en.wikipedia.org/wiki/Category:Upcoming_singles', false, $context);
print $file;
但是,我认为这不“合法”,作弊可不好。我认为维基百科必须提供任何其他用户代理来从外部应用程序获取其数据。
关于php - file_get_contents 对 'https://en.wikipedia.org/wiki/Category:Upcoming_singles' 的变量响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7681368/
我正在尝试根据 magento 中的产品 ID 在类别路径中获取类别名称。 假设我的产品 ID = 1,并且我在其中定义了 category5 (id = 5),并且我得到了类似 2/3/5 的类别路
我试图弄清楚如何通过 AngularJS 中的 $http.get() 方法发送数组。这就是我正在做的事情: $http.get('/events.json', {params: {category_
我在产品类别和子类别网站上工作,可以创建的子类别数量是无限的,这意味着我们可以自己拥有子类别的子类别。一切正常,我只是有一个问题:假设“PRODUCT 1”属于“SUB SUB CATEGORY 1”
在 stackoverflow 上所有这些 mod 重写主题之后,我仍然没有找到我的问题的答案。我有一个顶级站点,基本上我想做的就是将 /index.php?method=in&cat=Half+Li
我正在为我的未婚夫构建一个 Rails 应用程序来进行一些非常基本的库存跟踪。我们已经经历了几种选择,因为无论如何我都想学习 Rails,所以我们想出了为什么不。无论如何,如果我可以将一些产品按这样分
我需要在 Prestashop 主题的类别页面中列出同级类别。目前它确实显示子类别(如果有)但不兄弟类别。 如果能快速回答,我们将不胜感激!谢谢。 最佳答案 首先我会在/override/contro
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 7 年前。 Improve
我正在使用以下维基媒体 API 列出具有特定类别的所有页面:https://www.mediawiki.org/wiki/API:Categorymembers 例如https://en.wikipe
我应该如何命名用户类别和文章类别的表和模型?我有两个表,一个是用户,另一个是文章。我想对它们进行分类,以便我可以仅调用新闻文章或仅使用公司类别中的用户。所以我需要这些模型/表之间的关系。 我考虑过为文
在 UI Router 中实现此类功能的最佳方法是什么? /category/product /category/category/product 例如: /telephones/apple/ipho
我有以下 SQL 架构: tbl_产品: - ID - id_category tbl_categories: - ID - id_parent tbl_products_categories:- i
我需要创建一个对用户隐藏的应用程序。但在它被隐藏之前,我需要在 GUI 上设置一些配置,然后我必须从应用程序列表中隐藏图标。如果我删除 应用程序未显示在应用程序列表中。但是我的配置 GUI 也没有显
我正在尝试派生一个 MySQL 查询来转换这个: product | sold milk | 6 milk | 4 bread | 3 bread | 2 bread
我正在使用 ^category/|categories/$。 为什么 ^categor[y|ies]/$ 不起作用? 最佳答案 你的正则表达式应该是, ^categor(?:y|ies)/$ 使用非捕
据我所知,有两种情况会导致以下错误: ld: warning: instance method 'resetAudioSystem' in category from /opentok-ios-sdk
我希望我的问题很清楚,但我会尝试再解释一下。 在我的数据库中,我有两列名为“category”和“images”。在我的表单中,人们需要添加一个类别,以便我的 PHP 向 MySQL 添加一个新条目。
我在 pandas 中有以下 df 数据框: weekday venta_total_cy 0 Viernes 5.430211e+09 1 Lunes 3.4255
我目前陷入困境。场景是这样的。我有可能与多个类别相关联的产品。数据结构如下图: Products Table: product_id name 1 Lemon 2
我使用 openActivity()使用 Kotlin 在 Android Studio 3.1.2 中创建首选项 UI。 看来代码A和代码B都可以正常工作。 android.intent.categ
我有一个 Postgres 数据库。我正在尝试根据表 2 中表达的条件删除表 1 中的行。 表 1:id, object_id, time, action_type 表 2:object_id, ob
我是一名优秀的程序员,十分优秀!