Why do inner text is not active
Here is HTML code
[Here is HTML code]
<ul class="product">
<li class="product col-md-4 col-sm-4 col-xs-6 "><div class="product-header">
<a href="/so-mi-octopus-xanh-soc-trang-p5163098.html">
<img src="//cdn.nhanh.vn/cdn/store/17863/ps/20170925/0ctopus_thumb_450x600.jpg" class="attachment-shop_catalog size-shop_catalog wp-post-image">
</a><div class="buttons">
<a href="/so-mi-octopus-xanh-soc-trang-p5163098.html" rel="nofollow" class="button add_to_cart_button">
<i class="fa fa-shopping-bag" aria-hidden="true"></i>
<span class="screen-reader-text">Thêm vào giỏ</span></a>
<a data-product_id="5163098" class="button btnFav" rel="nofollow">
<i class="fa fa-heart-o" aria-hidden="true"></i>
<span class="screen-reader-text">Yêu thích</span>
</a></div></div><h3>Sơ mi Octopus xanh sọc trắng</h3><span class="price">
<span class="woocommerce-Price-amount amount">
400,000 ₫ </span>
</span></li>
</ul>
[Here is my code]
<?php
require "simple_html_dom.php";
$html=file_get_html("http://zuhaus.vn/zu-design-pc150502.html?page=1");
$ds=$html->find("ul.products li");
foreach ($ds as $sp) {
# code...
$price=$sp->find("span.price span",0);
echo $price;
$name=$sp->find("h3 a",1)->innertext;
echo $name;
}
?>
I have tried a lot of test case but it wont work :"<
Thanks you
P/s I used library simple_html_dom
If you want to get the contents of a tag and included in h3 then you have a syntax error in the line
$name = $sp->find("h3 a", 1)->innertext;
I suggest checking the syntax for the following
$name = $sp->find('h3', 1)->find('a', 1)->innertext;
the problem is with your selector, i changed the selector for the product name, and it just worked, also use curl to improve the fast of crawling
<?php
require "simple_html_dom.php";
$ch = curl_init("http://zuhaus.vn/zu-design-pc150502.html?page=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
$html = new simple_html_dom();
$html->load($curl_scraped_page);
$ds=$html->find("ul.products li");
foreach ($ds as $sp) {
# code...
$price=$sp->find("span.price span",0);
echo $price;
$name=$sp->find("a",3)->innertext; // this is where the problem on your code
echo $name;
echo "</br>";
}
?>
Related
I am trying to turn from UL / LI in this address list to text.
From This:
example
To this:
06.09.19 23:30 אור הנר 06.09.19 23:30 ~ שדרות, איבים
<h5 id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_alertsTitle">רשימת ההתרעות</h5>
<ul id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_ulAlertsList" class="more_result">
<li id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_rpt_ctl00_liArea" areaCode="0" time="">
<span><strong>06.09.19</strong></span>
<span class="border"><strong>23:30</strong></span>
<span class="span_area">אור הנר</span>
</li>
<li id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_rpt_ctl01_liArea" areaCode="0" time="">
<span><strong>06.09.19</strong></span>
<span class="border"><strong>23:30</strong></span>
<span class="span_area">שדרות, איבים</span>
</li>
</ul>
I try to do this in php..
thanks!!
<?php
$html = '<h5 id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_alertsTitle">רשימת ההתרעות</h5>
<ul id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_ulAlertsList" class="more_result">
<li id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_rpt_ctl00_liArea" areaCode="0" time="">
<span><strong>06.09.19</strong></span>
<span class="border"><strong>23:30</strong></span>
<span class="span_area">אור הנר</span>
</li>
<li id="ctl00_ContentPlaceHolder1_ucAlarmsGrid_rpt_ctl01_liArea" areaCode="0" time="">
<span><strong>06.09.19</strong></span>
<span class="border"><strong>23:30</strong></span>
<span class="span_area">שדרות, איבים</span>
</li>
</ul>';
$dom = new DOMDocument;
$dom->loadHTML($html);
foreach( $dom->getElementsByTagName('li') as $node)
{
echo $node->textContent . PHP_EOL;
}
I am new to PHP. I'd like an output similar to this:
<a title="icon-logo" href="http://localhost/projects/"><icon
class="icon"> </icon>About US</a>
But I am getting the following output:
<a title="icon-logo" href="http://localhost/projects/">About
US<icon class="icon"> </icon > </a>
I need an icon tag before text.
My Code
<?php
$item_output = 'About US';
$iconVar = "<icon class ='icon'> </icon>";
$output = preg_replace('/(<a.*?>[^<]*?)</', '$1'.$iconVar . "<", $item_output);
echo $output;
?>
Ignore the horrible code and formating, it's what I have to work with.
<div class="stories-pictures"><div class="inside">
<?php for ($j=0; $j<2; $j++) foreach ($stories as $post) { /* can be empty field as well*/
setup_postdata($post);
if ($post->ID==$mainID && $j==0) {
$link = get_permalink($productID);
$title = "Back to <br/>".get_the_title($productID);
$img = "<img class='backbg' width='316' height='234' src=".get_template_directory_uri()."/images/bg.png";
} else if ($post->ID!=$mainID && $j==1) {
$link = get_the_permalink()."?e=$productID";
$title = get_the_title();
$img = get_the_post_thumbnail(null,'story-thumb');
} else continue;
?>
<a href="<?php echo $link; ?>" class="storiespicture">
<span>
<span><em> <span class="title"><?php echo $title; ?></span></em></span>
</span>
<?php echo $img; ?>
<div class="storieoverlay">
</div> <!-- .storieoverlay -->
</a> <?php } ?>
</div></div>
Here's what's outputted:
<a href="http://hidden/" class="storiespicture">
<span>
<span> <em> <span class="title" style="background-color: rgba(144, 137, 213, 0.901961);">hidden</span></em> </span>
</span>
<img width="316" height="234" src="http://hidden/hidden.jpg" class="attachment-story-thumb wp-post-image" alt="hidden"> </a>
I'm trying to get the .storieoverlay class to be under the img.
I removed some possibly sensitive content, hence where hidden is shown.
It's because you don't close your image tag:
$img = "<img class='backbg' width='316' height='234' src=".get_template_directory_uri()."/images/bg.png";
Should be
$img = "<img class='backbg' width='316' height='234' src='".get_template_directory_uri()."/images/bg.png'>";
I've fixed the issue now.
It was a plugin outputting the mark up on this certain page, everything said here has been useful though, so thanks.
Well im having this problem and cant resolved it would like to have some help from you guys, so here it is:
I have this code:
<?php if (mysql_num_rows($tournaments) !=0){
do { ?>
<div id="mainContainer">
<div id="leftContainer">
<img src="images/tournaments/<?php echo $row_tournaments['logo']; ?>.png">
</div>
<div id="rightContainer">
<div id="rightContent">
<p><?php echo $row_tournaments['description']; ?></p>
<a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>">
<div id="galleryButton">
<p>Entrar no torneio</p>
</div>
</a>
</div>
<div id="rightDetails">
<i class="fa fa-gamepad"></i>
<a href="games.php?id_game=<?php echo $row_tournaments['id_game']; ?>">
<?php echo $row_tournaments['game']; ?>
</a>
<br>
<i class="fa fa-calendar-o"></i>
<a href="#">
<?php echo $row_tournaments['date']; ?>
</a>
<br>
<i class="fa fa-pencil-square-o"></i>
<a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>#disqus_thread">
Sem comentários
</a>
<br>
<script type="text/javascript">
function giveThatInputAValue(){
var elem = document.getElementById("search");
elem.value = "<?php echo $row_tournaments['city']; ?>";
/*document.forms["form"].submit();
*/}
</script>
<i class="fa fa-map-marker"></i>
<a onClick="giveThatInputAValue()">
<?php echo $row_tournaments['city']; ?>
</a>
<br>
<img src="images/<?php echo $row_tournaments['online']; ?>.png">
<a href="#">
<?php echo $row_tournaments['online']; ?>
</a>
</div>
</div>
</div>
<?php } while ($row_tournaments = mysql_fetch_assoc($tournaments));
} else {
?>
<div id="noresults">
<p>Sem torneios</p>
</div>
<?php } ?>
Everything loop fine but this part is not looping at all:
<script type="text/javascript">
function giveThatInputAValue(){
var elem = document.getElementById("search");
elem.value = "<?php echo $row_tournaments['city']; ?>";
/*document.forms["form"].submit();*/
}
</script>
And dont know why is it, someone please help. Cumps.
You are defining your function in a loop. Over and over again. So when you call your function, which one should it call? Probably all previous ones have been overwritten by the last version.
You should define your function outside of any loop and then call it with the parameters that you have available in the loop.
Apart from that you are also adding elements with ID's in your loop. ID's need to be unique as well so you should use classes or give them a unique ID.
a real php programmer knows this (meaning i am not one). been a while away from php.
ok first as i see it you never get your first row from result set (someone advise here). you are checking to see if you have rowcount then plod about. i reserve the right to be very wrong.
try something like
if ($result) {
while($row = mysql_fetch_array($result)) {
// output $row info
}
}
else {
echo "nada";
}
put your script for the function at the top
don't surround the main div section creations like you are with a loop
I'm working on my PHP to search for the elements. There are are one element called <p id='links'>, I use simple_html_dom method to parsing the contains from my script called get-listing.php.
Here is the example output from get-listing.php:
<p id='channels'>101 ABC FAMILY</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101'>http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>102 CBS</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=CBS&id=102'>http://www.mysite.com/get-listing.php?channels=CBS&id=102</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>103 CNN USA</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=CNN USA&id=103'>http://www.mysite.com/get-listing.php?channels=CNN USA&id=103</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>105 ESPN USA</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=ESPN USA&id=105'>http://www.mysite.com/get-listing.php?channels=ESPN USA&id=105</a>
</p>
<a id="aTest" href="rtmp://$OPT:rtmp-raw=rtmp://ny.iguide.to/edge playpath=49f5xnbs2wra0ut swfUrl=http://player.ilive.to/player_ilive_2.swf pageUrl=http://www.ilive.to token=UYDk93k#09sdafjJDHJKAD873">Stream 1</a>
<p id='channels'>106 FOX News</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=FOX News&id=106'>http://www.mysite.com/get-listing.php?channels=FOX News&id=106</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>107 Animal Planet</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=Animal Planet&id=107'>http://www.mysite.com/get-listing.php?channels=Animal Planet&id=107</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>108 USA Network</p>
<p id='links'>
<a href='http://www.mysite.com/get-listing.php?channels=USA Network&id=108'>http://www.mysite.com/get-listing.php?channels=USA Network&id=108</a>
</p>
<a id="aTest" href="">Stream 1</a>
Here is my PHP script:
<?php
ini_set('max_execution_time', 300);
$errmsg_arr = array();
$errflag = false;
$link;
include ('simple_html_dom.php');
$base1 = "http://www.mysite.com/get-listing.php";
$html = file_get_html($base1);
$countp = $html->find('p');
header("Content-type: text/xml");
$xml .= "<?xml version='1.0' encoding='UTF-8' ?>";
//echo $xml;
$xml .= '<tv generator-info-name="www.testbox.elementfx.com/xmltv">';
?>
I want to create the loops to get the url in each array from get-listing.php with one element id=links.
Can you please tell me how I can do that?
Assuming simple_html_dom.php gets your data as described here http://simplehtmldom.sourceforge.net/ then you should be able to use
foreach to go through the results
$links = $html->find('p[id=links] a');
foreach ($links as $link) {
//Get raw URL's here
$urls[] = $link->href;
}
EDIT
if you want to sort through the hrefs you could do a few simple tests here
foreach ($links as $link) {
//Get raw URL's here
if (strstr($link->href,'get_listing')) {
$listings[] = $link->href;
} else {
$general[] = $link->href;
}
}