我正在尝试学习PHP的DOM。似乎没有很多教程用于学习HTML查询。所以我问这个问题:
我运行了以下代码:
<?php
function DOMinnerHTML($element)
{
$innerHTML = "";
$children = $element->childNodes;
foreach ($children as $child)
{
$tmp_dom = new DOMDocument();
$tmp_dom->appendChild($tmp_dom->importNode($child, true));
$innerHTML.=trim($tmp_dom->saveHTML());
}
return $innerHTML;
}
$doc = new DOMDocument();
@$doc->loadHtmlFile("http://******/business_analyst");
$x = new DOMXpath($doc);
foreach ($x->query("//div[@class='content']") as $node)
{
echo DOMinnerHTML($node);
}
?>
这会返回以下内容:
<div class="content">
<p>
<span class="green"> | Elizabethtown Headquarters</span>
</p>
<p><strong>Summary</strong><br />
Working with Microsoft SQL Server, evaluate and utilize reporting tools, and work closely with other departments to determine business needs.</p>
<p><strong>Responsibilities</strong></p>
<ul>
<li>Communicate with other functional departments such as Finance, Sales/Marketing, Customer Service, Support Services and other departments to identify business needs.</li>
<li>Gather and formalize business requirements such as for reports, data extracts, third-party vendor application enhancements and internal application development.</li>
<li>Create simple and advanced queries using SQL structured for MS SQL Server.</li>
<li>Evaluate and utilize third-party reporting tools as needed depending on the required solution.</li>
<li>Perform database administration tasks as needed such as creating scheduled batch scripts, monitoring database performance and evaluating backup processes.</li>
<li>Prepare technical and user documentation as needed.</li>
<li>Write scripts and stored procedures as needed.</li>
<li>Work as part of a team to exchange business and technical knowledge in a positive manner.</li>
<li>Perform other duties as required related to analysis, requirements and database related projects.</li>
</ul>
<p><strong>Requirements</strong></p>
<ul>
<li>Minimum 3 years working with Microsoft SQL Server.</li>
<li>Minimum 3 years developing simple and complex SQL queries using MS SQL Server.</li>
<li>Experience writing batch scripts, stored procedures and stored functions.</li>
<li>Experience with business analysis related desktop tools such as Excel and Word.</li>
<li>Experience with third-party reporting tools.</li>
<li>Experience tuning SQL Server databases a plus.</li>
<li>Oracle and MySQL database experience a plus.</li>
<li>Professional attitude and willingness to work independently and as a member of a team.</li>
<li>A.S. Degree and/or B.S. Degree preferred but not required depending on years of experience.</li>
</ul>
<h2>Apply Now</h2>
<form class="careers-form" id="business_analyst" method="post" action="http://web1.bluegrasscellular.com/" enctype="multipart/form-data" >
<div class='hiddenFields'>
<input type="hidden" name="ACT" value="20" />
<input type="hidden" name="URI" value="about/careers/business_analyst" />
<input type="hidden" name="XID" value="" />
<input type="hidden" name="status" value="open" />
<input type="hidden" name="return" value="/contact/thanks/%%entry_id%%" />
<input type="hidden" name="redirect_on_duplicate" value="" />
<input type="hidden" name="RET" value="http://web1.bluegrasscellular.com/about/careers/business_analyst" />
<input type="hidden" name="form_name" value="careers" />
<input type="hidden" name="ajax_request" value="y" />
<input type="hidden" name="params_id" value="13930914" />
<input type="hidden" name="site_id" value="1" />
</div>
<fieldset>
<input type="hidden" name="job_title" value="Business Analyst" />
<input type="hidden" name="job_description" value="Business Analyst" />
<input type="hidden" name="source" value="website-careers" id="source">
<input type="hidden" name="message" value="0bba03eb0000000000000000000000071a5c" id="message">
<input type="hidden" name="job_location" value="Elizabethtown Headquarters" />
<label><span class="red">*</span>Name:</label>
<input type="text" name="name" /><br />
<label><span class="red">*</span>Email:</label>
<input type="text" name="email" /><br />
<label><span class="red">*</span>Resume:</label>
<input type="file" name="file1" />
<label><span class="red">*</span>Please enter the text as it appears in the box below</label>
<script type="text/javascript" src="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
window.onload = function(){
Recaptcha.create('6LduXdcSAAAAAEjc_hSNGCFG-BurosYW8a49xmgv',
"recaptcha_container",
{
theme:'red',
lang:'en'
}
);
};
</script>
<div id="recaptcha_container"></div>
<div class="float-clear enews-optin">
<input class="check" style="display: inline; float:left; width: 16px; margin-right: 8px;" type="checkbox" name="enews" value="yes"/>
<label class="check" style="display: inline; padding: 1px; margin: 0; float: left;">Yes, sign me up to receive email updates from Bluegrass Cellular with information on the latest products, services, special offers and discounts.</label>
</div>
<input class="submit-btn" type="submit" /><br>
<p class="float-clear"><small><span class="red">*required</span></small></p>
</fieldset>
</form>
<p><a href="/about/careers/">Back to Jobs</a></p>
</div><!-- /.content-->
我想抓住强有力标题下的内容(摘要,责任,要求)。由于我似乎无法在网上找到很多帮助,我在这里寻求你的帮助!谢谢!
答案 0 :(得分:0)
如果您只想要<strong>
个节点的内容,只需将您的XPath查询更新为以下内容:
//div[@class='content']//strong/text()
您还可以使用
检索<strong>
个节点
//div[@class='content']//strong
然后从PHP中检索值。