[英]PHP Simple DOM Parser Parse Current PHP Page
I am using the PHP Simple DOM parser to extract all of the image sources on a given page like so: 我正在使用PHP Simple DOM解析器来提取给定页面上的所有图像源,如下所示:
// Include the library
include('simple_html_dom.php');
// Retrieve the DOM from a given URL
$html = file_get_html('http://google.com/');
// Retrieve all images and print their SRCs
foreach($html->find('img') as $e)
echo $e->src . '<br>';
Instead of using Google.com, I wish to use a page on Wordpress's admin (backend) area. 我希望不使用Google.com,而希望使用Wordpress的管理(后端)区域中的页面。 These pages are PHP pages, not HTML (but the page has standard HTML throughout).
这些页面是PHP页面,而不是HTML页面(但该页面始终具有标准HTML)。 How would I use the current page as the
$html
variable? 如何将当前页面用作
$html
变量? PHP newbie over here. PHP新手在这里。
Using this library dxtool found here . 使用此库dxtool可以在此处找到。
require 'WebGet.php';
$w = new WebGet();
// using cache to prevent repetitive download
$w->useCache = true;
$w->cacheLocation = '/tmp';
$w->cacheMaxAge = 3600;
$w->cookieFile = '/tmp/cookie.txt';
// $login_get_data and $login_post_data is associative array
$login = $w->requestContent($login_url, $login_get_data, $login_post_data);
// $image_page_url is the url of the page where your images exist.
$image_page = $w->requestContent($image_page_url);
$dom = new DOMDocument();
$dom->loadHTML($image_page);
$imgs = $dom->getElementsByTagName("img");
foreach($imgs as $img){
echo $img->getAttribute("src");
}
Disclaimer: I am the author of this class 免责声明:我是此类的作者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.