- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
$url = 'http://www.w3schools.com/js/js_loop_for.asp';
$html = @file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xml = @simplexml_import_dom($doc);
$images = $xml->xpath('//img');
var_dump($images);
die();
输出是:
array(0) { }
但是,在页面源代码中我看到了这个:
<img border="0" width="336" height="69" src="/images/w3schoolslogo.gif" alt="W3Schools.com" style="margin-top:5px;" />
编辑:它出现$html
的内容停止在 <body>
此页面的标记。知道为什么吗?
最佳答案
It appears $html's contents stop at the tag for this page. Any idea why?
是的,您必须为该页面提供有效的用户代理。
$url = 'http://www.w3schools.com/js/js_loop_for.asp';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_exec($ch);
输出所有内容到结尾 </html>
包括您要求的 <img border="0" width="336" height="69" src="/images/w3schoolslogo.gif" alt="W3Schools.com" style="margin-top:5px;" />
当没有用户代理的简单 wget 或 curl 仅返回到 <body>
标签。
$url = 'http://www.w3schools.com/js/js_loop_for.asp';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
$doc = new DOMDocument();
$doc->loadHTML($html);
$xml = simplexml_import_dom($doc);
$images = $xml->xpath('//img');
var_dump($images);
die();
编辑: 我的第一篇文章指出 xpath 仍然存在问题...我只是没有尽职调查,上面更新的代码运行良好。我忘记强制 curl 输出到字符串而不是打印到屏幕(默认情况下是这样)。
关于php - 为什么我在这里没有取回任何图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5719328/
如何处理在 EditText 上键入时按返回键的事件?当显示虚拟键盘并且用户按回时,它会被隐藏。我想处理这个事件,但是在 EditText 中设置 OnKeyListener 并没有帮助。 最佳答案
我编写了 SMS 应用程序,并为其编写了 BroadcastReceiver。我想从 BroadcastReceiver 获取数据到我的 Activity 中,那么我该如何获取呢。 我的广播接收器代码
有一个场景,其中 httpentity 在 InputStream 中有图像的二进制数据,为了进一步处理,它被转换为库文件中的字符串 [String str = EntityUtils.toStrin
如何获取 uiwebview 的返回和转发 URL。我想要 URL,以便我可以相应地启用和禁用我的网络浏览器上的后退和前进按钮 谢谢 最佳答案 UIWebView 包含后退或前进的构建方法 只需使用执
CGRect rect = Temp_3_Artwork_Big_Image.frame; NSLog(@"Rect : %.2f,%.2f,%.2f,%.2f",rect.origin.x,rect
在返回旧项目并更新其依赖项后,我必须意识到,自版本 1.1.5 以来,logback 不再将 MDC 传播给子项:https://github.com/qos-ch/logback/commit/aa
holder.js 我想向我的页面动态添加占位符图像。 这样插入是行不通的: $('',{class:'file-item'}) .append($('',{'data-src':'holde
我在 C# 中使用 ExecuteOracleNonQuery 来使用存储过程将记录插入到我的 Oracle 数据库中,但似乎无法返回 ROWID。 在 C# 中 ... using (OracleC
我正在努力将一条记录插入到 postgresql 中: val res = DB.withConnection { implicit con => SQL(
我是新手,正在尝试使用 React 和 Redux 构建一个简单的书签应用程序。 我无法解决这个问题: 用户可以创建一个书签并将其添加到多个文件夹。所以我发送一个 addMark(bookmark)
我有一个像下面这样的网址 /pages/edit_product/11 在我的行动 edit_product我怎样才能得到 id 11 这样我就可以做@p = Product.find_by_id(1
我在php中有一个外部文件,输出为json格式 我希望数据以数组的形式发送回 jquery ....该怎么做? php: $options = "data 0 data 1 data 2 data 3
我有以下 C++ 代码: __declspec(dllimport) char* get_mac() { size_t byteToAlloc = 17; char *mac_addr
我正在编写一个 Azure 函数,该函数从 Microsoft 获取 OAuth token ,我已经成功获取了该 token 。我正在尝试使用该 token 访问 Microsoft Graph。我
我有一个 Python Google App Engine 应用程序,我想在 Emacs 中的开发服务器上进行调试。我创建了一个 pdb 可执行文件,以便在 Emacs 中进行调试: $ which
我正在开发一个 google chrome 扩展程序,需要在其中对 Twitch 上的用户进行身份验证。根据https://github.com/justintv/Twitch-API/blob/ma
我有一个简单的 Web API,它返回一个 Iobservable。我正在使用 HttpClient 获取 Observable,以便我可以订阅它。我的问题是订阅时返回的 Iobservable 发出
我正在使用 Ionic 2 构建 Web 应用程序的移动版本,该应用程序使用 SAML 进行 SSO,在我的客户端服务器上运行。现在我们有一个 api,当您未登录网站时会调用它,该网站会重定向到他们的
几个月前,我创建了一个使用 oauth2 与谷歌进行身份验证的 rails 应用程序 - 特别是 omniauth-google-oauth2 gem。我已经完成了创建身份验证和存储刷新 token
我正在尝试将一个值作为 JSON 从我的后端传递到我的应用程序的前端。我目前正在运行 express.js 并且所有发布方法的连接都是完美的。 在我的应用程序的前端单击按钮后,我想从我的服务器取回发票
我是一名优秀的程序员,十分优秀!