php - 如何使用 Simple HTML DOM PHP 获取 span data-reactid 值?
问题描述
这些都不起作用:
$html = file_get_html("https://www.example.com/page/");
print($html->find('[data-reactid=10]', 0)->plaintext);
print($html->find('[data-reactid=11]', 0)->plaintext);
html 看起来像这样:
<div class="stuff" data-reactid="10">
<span data-reactid="11">Value I want</span>
</div>
我究竟做错了什么?
供参考。这确实有效:
print($html->find('[data-reactid=5]', 0)->plaintext);`
在哪里:
<div class"stuff" data-reactid="5">
<!-- react-text: 6 -->
Value I want
<!-- /react-text: -->
</div>
那么如何通过跨度获得值?我可以通过 div 获取值。
解决方案
这行得通。
$html_str = '
<div class="stuff" data-reactid="10">
<span data-reactid="11">Value I want</span>
</div>
';
// Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($html_str);
// Get the value
echo $html->find('div[data-reactid=10]', 0)->find('span', 0)->{'data-reactid'};
推荐阅读
- c - 0600 在函数中是什么意思?和\200一样吗?
- java - 当 BufferedReader.read(char[]) 返回-1?
- reactjs - 为什么我收到 TypeError:无法读取未定义的属性“地图”
- java - Maven命令行执行错误ClassNotFoundException
- postgresql - 如何在查询生成器中使用 NOT LIKE?
- orchardcms - 您如何在 Orchard Core 中创建分类法?
- python - 如何使用传入的串行数据更新 Tkinter Canvas 中的对象?
- javascript - 我可以使用 javascript 滚动事件更改 div 的宽度和高度吗?
- variables - 关于 Daniel Shiffman 的“学习处理”中的全局变量与局部变量示例
- python - 从 docx 中的不同行中提取数据