I am trying to extract some text from a webpage. I’ve tried something like:
var headings = document.evaluate("//div[contains(., 'Location')]", document, null, XPathResult.ANY_TYPE, null );
but it returns the whole containing div. I just want to extract the text “Town Center”. So basically, the smallest element containing that text.
Here’s an edited and shortened model of the webpage.
<html lang="en" class="h-100">
<head>
<!-- ****************** CONTENT STARTS ****************** -->
<div class="container-fluid px-1">
<div class="row row-offcanvas row-offcanvas-left">
<div class="col-sm-5 col-md-4 col-lg-3 sidebar-offcanvas leftnav-row-padding" id="grantFamily">
</div>
<div class="col-sm-7 col-md-8 col-lg-9">
<div class="col-sm-10"><h1 role="heading"><span class="fa fa-folder-open text-gf" aria-hidden="true"></span>Title</h1></div>
</div>
<div class="card mb-3" id="grant-title-panel">
<div class="card-header bg-primary text-white">
<div class="row vertical-align-center">
<div class="col-sm-6">
<a class="text-white fw-bold" href="xxx" title="Snapshot" target="_blank"><u>XXXXXX</u></a>
</div>
<div class="col-sm-6 text-end">
<span>Appl ID: 12345</span>
</div>
</div>
</div>
<div class="card-body">
<div class="row mb-3">
<div class="col-sm-6">
<strong>Name</strong>
<div>Doe, John
</div>
</div>
<div class="col-sm-6">
<strong> Title</strong><div>Blah Blah</div>
</div>
</div>
<div class="row mb-3">
<div class="col-sm-6">
<strong>Status</strong> <div>Ready<br/></div>
</div>
<div class="col-sm-6">
<strong>Location</strong> <span class="text-uppercase"><div>Town Center</div></span>
</div>
</div>
<div class="row mb-2 gf-grey-bg">
<div class="col-sm-6 mb-2">
<strong>Checklist</strong>
<div>Not Started</div>
</div>
</div>
</div>
</div>
1