How do I find a div in PHP using HTML DOM which has spaces in its classname.
Snippet
<div class="f14 rel">
<input type="checkbox" class="p0m0 mr_5" name="propid[]" id="X6849129" value="X6849129"/>
<div id="imgChkBoxX6849129">
<a id="desc_X6849129" class="f14 uline" target="_blank" href="some link"/>
</div>
I tried $html->find('div."f14 rel"').But it doesn't work.Neither does $html->find('div.f14 rel')
Related
I have code like this, and it's fetching data from other website.
require('simple_html_dom.php');
$html = file_get_html("www.example.com");
$info['diesel'] = $html->find(".on .price",0)->innertext;
$info['pb95'] = $html->find(".pb .price",0)->innertext;
$info['lpg'] = $html->find(".lpg .price",0)->innertext;
The html code from other website looks:
<a href="#" class="station-detail-wrapper on text-center active">
<h3 class="fuel-header">ON</h3>
<div class="price">
5,97
<span>zł</span>
</div>
</a>
So if i use echo $info['diesel'] it shows me 5,97 zł. I would like to delete this <span>zł</span> to show price only.
May be you can replace that span tag with blank:
echo $info['diesel']=str_replace("<span>zł</span>","",$info['diesel']);
I have a html code with many html tables. I want to extract links from specific one which has specific div above.
Here's my sample code:
<div class="boxuniwersal_header">Table 1</div>
<img src="img/boxuniwersal_top.gif" width="210" height="18" alt="" style="margin-top: 5px" />
<div class="boxuniwersal_content">
<div class="boxuniwersal_subcontent">
<div class='menu_m1'><table cellpadding="3"><tr><td><img src="some.jpg" width="45" /></td><td>Some text</td></tr></table></div>
<br />
</div>
</div>
<!-- /box -->
<!-- box -->
<div class="boxuniwersal_header">Table 2</div>
<img src="img/boxuniwersal_top.gif" width="210" height="18" alt="" style="margin-top: 5px" />
<div class="boxuniwersal_content">
<div class="boxuniwersal_subcontent">
<div class='menu_m1'><table cellpadding="3"><tr><td><img src="some2.jpg" width="45" /></td><td>Some text2</td></tr></table></div>
<br />
</div>
</div>
$domXPath = new DOMXPath($domDocument);
$results = $domXPath->query("//div/div/table/tr/td/a|//table//tr/td//a"); //querying domdocument
foreach($results as $result)
{
$links[]=$result->getAttribute("href");
}
This code returns all links. I want to grab only links from Table1. Is it possible?
Your main problem is just tuning the XPath expression to select the right XML.
If you change your XPath to
//div[text()="Table 1"]/following-sibling::div[1]//table//a
What this does is first find the <div> element whose text is the one your after.
The following-sibling::div[1] part will look at the first <div> element at the same level as the <div> element already selected (this is the one where the <table> is).
The last part just looks for all <a> elements within the enclosing <table>.
I am using Simple HTML DOM parser to fetch some data. Everything works great but I am facing a problem when I have enabled the read more plugin on my WordPress site.
The hidden content (the rest content of the article) is inside this div.
A sample:
<div class="mycontent">
Here is some content
<div class="brm" style="display: none;">
Here is another content but it's not vissible because the style of this div is set to display:none
</div>
<p>read more..</p>
</div>
So far I am using:
$url = "www.myurl.com";
$html = new simple_html_dom();
$html->load_file($url);
$maindiv = $html->find('div.mycontent',0)->outertext;
it displays everything except the content inside the div <div class="brm" style="display: none;">
Any ideas how to get the hidden content?
It actually does get that div:
include 'simple_html_dom.php';
$str = <<<EOF
<script type="text/javascript">
<div class="mycontent">
Here is some content
<div class="brm" style="display: none;">
Here is another content but it's not vissible because the style of this div is set to display:none
</div>
<p>read more..</p>
</div>
EOF;
$html = str_get_html($str);
echo $html->find('div.mycontent',0)->outertext;
// <div class="mycontent"> Here is some content <div class="brm" style="display: none;"> Here is another content but it's not vissible because the style of this div is set to display:none </div> <p>read more..</p> </div>
I got blocks of div hyperlinks as string in $code. This is example of blocks found in $code:
<div id="" class="thumbo">
</div>
i want to replace everything before 4th slash with ./doit.php.id=
For example i want change this :
<div id="" class="thumbo">
</div>
to
<div id="" class="thumbo">
</div>
The problem is that data before last 4th slash is dynamic and wonder how i can replace them all with ./doit.php?id=?
I have a HTML file that I'm trying to parse. It has a bunch of DIVs like this:
<div class="doc-overview">
<h2>Description</h2>
<div id="doc-description-container" class="" style="max-height: 605px;">
<div class="doc-description toggle-overflow-contents" data-collapsed-height="200">
<div id="doc-original-text">
Content of the div without paragraph tags.
<p>Content from the first paragraph </p>
<p>Content from the second paragraph</p>
<p>Content from the third paragraph</p>
</div>
</div>
<div class="doc-description-overflow"></div>
</div>
I tried this:
foreach($html->find('div[id=doc-original-text]') as $div) {
echo $div->innertext;
}
You notice that I directly find the doc-original-text but I also tried to parse from outer divs to inner divs.
Try This,
foreach($html->find('div#doc-original-text') as $div) {
echo $div->innertext;
}