如何在 php DOMXPath 对象中 return?
How to return in php DOMXPath object?
Now found query if '$NotXP->query' = query return string?!
如何制作下一个代码?
$xp = new \DOMXPath(@\DOMDocument::loadHTMLFile($url));
$list = $xp->query('//table[@class="table-list quality series"] tbody');
$link = $list->query('//tr[@class="item"]');
$arr_links = [];
foreach ($link as $link_in_cycle) {
$link_quality = $link_in_cycle->query('//td[@class="column first video"]');
$link_audio = $link_in_cycle->query('//td[@class="column audio"]');
$link_size = $link_in_cycle->query('//td[@class="column size"]');
$link_seed = $link_in_cycle->query('//td[@class="column seed-leech"] span[@class="seed"]');
$link_download_url = $link_in_cycle->query('//td[@class="column last download"] a')->getAttribute("data-default");
html 请求来源@nigel-ren
从这段代码中需要获取信息
<tbody>
<tr class="item">
<td class="column first video">720x400</td>
<td class="column audio">mp3</td>
<td class="column size">5.70 Gb</td>
<td class="column seed-leech">
<span class="seed">15</span>
<span class="leech">26</span>
</td>
<td class="column updated">07.07.2017</td>
<td class="column consistence"><a href="javascript:void(0);" title="title in td" data-type="torrent-consistence" class="show-modal show-consistence" data-route="/hashinfo/12345?fields=files"></a></td>
<td class="column last download">
<a class="button middle rounded download zona-link"
data-type="download"
data-zona="0"
data-torrent=""
data-default="url_data"
data-not-installed=""
data-installed=""
data-metriks="{'eventType': 'click', 'data' : { 'type': 'show_download', 'id': '84358'}}"
title="text in title" href="javascript:void(0);" >Download</a> </td>
我做了一些更改以帮助我调试代码。最主要的是你的 XPath 表达式无效,你总是可以尝试像 FreeFormatter 这样的网站,它允许你用一些示例源检查你的表达式。
$doc = new \DOMDocument();
$doc->loadHTMLFile($url);
$xp = new \DOMXPath($doc);
$list = $xp->query('//table[@class="table-list quality series"]//tr[@class="item"]');
$arr_links = [];
foreach ($list as $link_in_cycle) {
$link_quality = $xp->query('//td[@class="column first video"]/text()', $link_in_cycle)[0]->wholeText;
$link_audio = $xp->query('//td[@class="column audio"]/text()', $link_in_cycle)[0]->wholeText;
$link_size = $xp->query('//td[@class="column size"]/text()', $link_in_cycle)[0]->wholeText;
$link_seed = $xp->query('//td[@class="column seed-leech"]//span[@class="seed"]/text()', $link_in_cycle)[0]->wholeText;
$link_download_url = $xp->query('//td[@class="column last download"]//a/@data-default', $link_in_cycle)[0]->value;
echo $link_quality.PHP_EOL;
echo $link_audio.PHP_EOL;
echo $link_size.PHP_EOL;
echo $link_seed.PHP_EOL;
echo $link_download_url.PHP_EOL;
}
XPath 表达式尝试检索每个元素中的文本节点,这将 return 所有节点的列表,此代码假定实际内容周围没有任何空格(并使用[0] 获取列表的第一个元素)。 wholetext
只是 DOMText 元素的实际内容。
根据您提供的样本内容(加上我不得不发明的周围部分),它给出了...
720x400
mp3
5.70 Gb
15
Download
Now found query if '$NotXP->query' = query return string?!
如何制作下一个代码?
$xp = new \DOMXPath(@\DOMDocument::loadHTMLFile($url));
$list = $xp->query('//table[@class="table-list quality series"] tbody');
$link = $list->query('//tr[@class="item"]');
$arr_links = [];
foreach ($link as $link_in_cycle) {
$link_quality = $link_in_cycle->query('//td[@class="column first video"]');
$link_audio = $link_in_cycle->query('//td[@class="column audio"]');
$link_size = $link_in_cycle->query('//td[@class="column size"]');
$link_seed = $link_in_cycle->query('//td[@class="column seed-leech"] span[@class="seed"]');
$link_download_url = $link_in_cycle->query('//td[@class="column last download"] a')->getAttribute("data-default");
html 请求来源@nigel-ren
从这段代码中需要获取信息
<tbody>
<tr class="item">
<td class="column first video">720x400</td>
<td class="column audio">mp3</td>
<td class="column size">5.70 Gb</td>
<td class="column seed-leech">
<span class="seed">15</span>
<span class="leech">26</span>
</td>
<td class="column updated">07.07.2017</td>
<td class="column consistence"><a href="javascript:void(0);" title="title in td" data-type="torrent-consistence" class="show-modal show-consistence" data-route="/hashinfo/12345?fields=files"></a></td>
<td class="column last download">
<a class="button middle rounded download zona-link"
data-type="download"
data-zona="0"
data-torrent=""
data-default="url_data"
data-not-installed=""
data-installed=""
data-metriks="{'eventType': 'click', 'data' : { 'type': 'show_download', 'id': '84358'}}"
title="text in title" href="javascript:void(0);" >Download</a> </td>
我做了一些更改以帮助我调试代码。最主要的是你的 XPath 表达式无效,你总是可以尝试像 FreeFormatter 这样的网站,它允许你用一些示例源检查你的表达式。
$doc = new \DOMDocument();
$doc->loadHTMLFile($url);
$xp = new \DOMXPath($doc);
$list = $xp->query('//table[@class="table-list quality series"]//tr[@class="item"]');
$arr_links = [];
foreach ($list as $link_in_cycle) {
$link_quality = $xp->query('//td[@class="column first video"]/text()', $link_in_cycle)[0]->wholeText;
$link_audio = $xp->query('//td[@class="column audio"]/text()', $link_in_cycle)[0]->wholeText;
$link_size = $xp->query('//td[@class="column size"]/text()', $link_in_cycle)[0]->wholeText;
$link_seed = $xp->query('//td[@class="column seed-leech"]//span[@class="seed"]/text()', $link_in_cycle)[0]->wholeText;
$link_download_url = $xp->query('//td[@class="column last download"]//a/@data-default', $link_in_cycle)[0]->value;
echo $link_quality.PHP_EOL;
echo $link_audio.PHP_EOL;
echo $link_size.PHP_EOL;
echo $link_seed.PHP_EOL;
echo $link_download_url.PHP_EOL;
}
XPath 表达式尝试检索每个元素中的文本节点,这将 return 所有节点的列表,此代码假定实际内容周围没有任何空格(并使用[0] 获取列表的第一个元素)。 wholetext
只是 DOMText 元素的实际内容。
根据您提供的样本内容(加上我不得不发明的周围部分),它给出了...
720x400
mp3
5.70 Gb
15
Download