<div id="archive_content_block">
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="archive_cat_caption">
<h4>অর্থনীতি</h4>
</div>
<ul>
<li><i class="fa fa-square-o"></i>
<a href="http://67.227.189.112/~rtvnews24/economy/2126/বাধ্যতামূলক-করারোপের-প্রস্তাব-অর্থমন্ত্রীর">
<font style="color:rgb(33, 33, 33)">বাধ্যতামূলক করারোপের প্রস্তাব অর্থমন্ত্রীর</font>
</a>
</li>
</ul>
</div>
<div class="col-md-6 col-sm-6">
<div class="archive_cat_caption">
<h4>খেলাধুলা</h4>
</div>
<ul>
<li><i class="fa fa-square-o"></i> <font style="color:rgb(33, 33, 33)">অস্ট্রেলিয়া রেকর্ড</font></li>
</ul>
</div>
</div>
</div>
[this is my scraping html page code]
here i have a function which for get scraping title and link. but not work
public function get_dom()
{
$this->load->library('scraping');
$date = date('Y/m/d'); // custom date
$url = "http://67.227.189.112/~rtvnews24/archive/$date"; //my link
$html = file_get_html($url);
$row = $html->find('div.archive_content_block',0); // select content
foreach($row->find('div.archive_cat_caption', 0) as $title) {
echo $title->find('h4', 0)->plaintext.'</br>'; //title
foreach($row->find('ul',0) as $link) {
echo $link->find('li',0)->find('a', 0)->href.'</br>'; //link
}
}
}
here i am try to get title and link. please help me. Thanks in advance
Related
I'm trying to insert the following 'block' of HTML using Element.insertAdjacentHTML()
<div class="content-wrapper">
<ul>
<li class="go-back-environment">
<a href="/environment">
<p>Back to Environment</p>
</a>
</li>
<li class="back-home">
<a href="/home">
<p>Back to home</p>
</a>
</li>
</ul>
</div>
However, I'm not sure it is possible to add divs with classes and lists. I've been trying to find (unsuccessfully) articles with examples where more than one 'p' or 'span' was added.
I started with the following but I don't know how to continue building:
var footer = document.getElementById ('environment');
footer.insertAdjacentHTML('afterend','')
I tried the following:
<script>
var footer = document.getElementById ('environment');
footer.insertAdjacentHTML('afterend',
'<div class="content-wrapper">
<ul>
<li class="go-back-environment">
<a href="/environment">
<p>Back to Environment</p>
</a>
</li>
<li class="back-home">
<a href="/home">
<p>Back to home</p>
</a>
</li>
</ul>
</div> ');
</script>
Is it even possible ?
Thanks !
Yes, it is. Try using template literals for longer html strings:
var footer = document.getElementById('footer');
var html = `
<div class="content-wrapper">
<ul>
<li class="go-back-environment">
<a href="/environment">
<p>Back to Environment</p>
</a>
</li>
<li class="back-home">
<a href="/home">
<p>Back to home</p>
</a>
</li>
</ul>
</div>
`;
footer.insertAdjacentHTML('afterend', html);
<main>Main</main>
<footer id="footer">Footer</footer>
Looks like you have done some mistake in string
Check for this
var footer = document.getElementById('environment');
var appendHtml = ['<div class="content-wrapper">',
'<ul>',
'<li class = "go-back-environment">',
'<a href = "/environment">',
'<p> Back to Environment </p>',
'</a>',
'</li>',
'<li class = "back-home">',
'<a href = "/home">',
'<p> Back to home </p>',
'</a>',
'</li>',
'</ul>',
'</div>'].join("");
footer.insertAdjacentHTML('afterend', appendHtml);
<div id=environment>Footer Div</div>
Thanks for previous helps. Am here with another one.
Ok, so i am retrieving data from database.. its working fine, but where i have issues is that after the data spans the first row it doesn't start from the first column of the next row.. I don't know how to explain this better ... but I'I'll add the code and image here....
<div class="row">
<?php
$selectCat = "SELECT * FROM categories ORDER BY cat_id DESC";
$selectCatKwary = mysqli_query($link, $selectCat);
$catCount = mysqli_num_rows($selectCatKwary);
if ($catCount > 0) {
?>
<?php
while ( $catRow = mysqli_fetch_array($selectCatKwary)) { ?>
<a href="">
<div class="col-lg-3 col-sm-6">
<div class="card">
<div class="content">
<div class="row">
<div class="col-xs-5">
<div class="icon-big icon-warning text-center">
<i class="ti-user"></i>
</div>
</div>
<div class="col-xs-7">
<div class="numbers">
<p class="text-uppercase text-bold"><?php echo $catRow['catTitle']; ?></p>
105GB
</div>
</div>
</div>
</div>
</div>
</div>
</a>
<?php } } ?>
</div>
and here is the image
The first four data resolved well... the next one which MOBILE CARS did not start from the beginning column, and also affected others
My problem is handlebars don't operate Json data output. I don't understand this problem. How can i handle it???
This is my JSON data
{
"boardInfo":
[
{"no":1,"title":"히히","url":null,"writerNick":"cheolhan","contents":"하하","createdDate":"2016-10-24","createdDate2":"2016-10-24","like":0,"viewCount":19,"email":null,"userNo":"1","categoryNo":2,"category":"스포츠","linkTitle":null,"linkURL":null,"linkDetailUrl":null,"linkImage":null,"linkDesc":null,"userProfilePath":null},
{"no":2,"title":"히히","url":null,"writerNick":"cheolhan","contents":"하하","createdDate":"2016-10-24","createdDate2":"2016-10-24","like":0,"viewCount":15,"email":null,"userNo":"1","categoryNo":2,"category":"스포츠","linkTitle":null,"linkURL":null,"linkDetailUrl":null,"linkImage":null,"linkDesc":null,"userProfilePath":null},
{"no":3,"title":"후후","url":null,"writerNick":"cheolhan","contents":"후후","createdDate":"2016-10-24","createdDate2":"2016-10-24","like":0,"viewCount":276,"email":null,"userNo":"1","categoryNo":2,"category":"스포츠","linkTitle":null,"linkURL":null,"linkDetailUrl":null,"linkImage":null,"linkDesc":null,"userProfilePath":null}
]
}
This is script code
var source = $('#liTemplateText').html();
var template = Handlebars.compile(source);
var data = result.data.boardInfo
data.stringify = JSON.stringify(data);
console.log(data)
var boards = template(data);
$("#post_wrapper").append(boards);
{{#each data}}
<li id="each_post_wrap">
<div id="each_post">
<div id="user_Nick">
<img class="user_Nonepht userInfoLink" src="/TeamProject/upload/{{userProfilePath}}" alt="userImg" data-userNo="{{userNo}}" data-userNick="{{writerNick}}">
<span class="userInfoLink" data-userNo="{{userNo}}" data-userNick="{{writerNick}}">{{writerNick}}</span>
</div>
<div class="post_photoWrap titleLink" data-no="{{no}}" data-userNo="{{userNo}}">
<a href="#">
<img src="{{linkImage}}" alt="Image File">
</a>
</div>
<a class="post_contsWrap">
<span class="each_post_title titleLink" data-no="{{no}}" data-userNo="{{userNo}}">{{title}}</span>
<span class="each_post_contents titleLink" data-no="{{no}}" data-userNo="{{userNo}}"><p>{{{contents}}}</p></span>
</a>
<div class="post_ctgWrap">
<span class="categoryLink" data-ctgNo="{{categoryNo}}">{{category}}</span>
</div>
<div class="post_BtnWrap">
<div class="post_leftBtn">
<img class="viewCount" src="/TeamProject/mainpage/mainpage_images/viewCount.png" alt="view">
<span>{{viewCount}}</span>
</div>
<div class="post_rightBtn">
<img class="like_Onclick" src="/TeamProject/mainpage/mainpage_images/likeOnClick.png" alt="like">
<span>{{like}}</span>
</div>
<div>
</div>
</li>
{{/each}}
This is HTML code
<div id="tabs" class="all_post_wrap">
<ul id="post_wrapper" class="tabs-1-contents">
</ul>
</div>
Any help much appreciated.
I've made a list with <li> tags which looks like this.
https://gyazo.com/764cbe3542522bc552d774e1383ac810
Why is there a random <li> tag down there? There is nothing there to say at all?
<center>
<div class="site-wrapper-inner">
<div class="cover-container">
<div class="inner cover" style="text-align:left;margin-top:30px;">
<div class="card card-outline-primary">
<div class="card-header card-primary">
Database breaches
</div>
<div class="card-block">
<p>Here is a list of all databases that have been added to our search engine.</p>
<li>
<p>
<?php
$this->load->database();
$this->db->from('databases');
$query = $this->db->get();
foreach($query->result() as $q) {
?>
<?=$q->Website?> hacked on
<?=$q->Date?> with
<?=$q->Users?> users
<br />
<li>
<p>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</center>
Here is a version of your exact code but I ran the "tidy" function in the snippet. See how it's broken?
You're not closing things properly, see the code comments. Also, you're incorrectly nesting the tags, the li is closed before the p even though it starts before it.
Technically, you're adding a new li element when you're trying to close the tag because instead of </li> you're doing <li>.
<center>
<div class="site-wrapper-inner">
<div class="cover-container">
<div class="inner cover" style="text-align:left;margin-top:30px;">
<div class="card card-outline-primary">
<div class="card-header card-primary">
Database breaches
</div>
<div class="card-block">
<p>Here is a list of all databases that have been added to our search engine.</p>
<li>
<p>
<?php $this->load->database(); $this->db->from('databases'); $query = $this->db->get(); foreach($query->result() as $q) { ?>
<?=$q->Website?> hacked on
<?=$q->Date?> with
<?=$q->Users?> users
<br />
<li> <!-- NOT A CLOSING TAG -->
<p> <!-- NOT A CLOSING TAG, ALSO SHOULD BE BEFORE THE CLOSING LI TAG -->
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</center>
I want to help my problem is: I get the data but the data obtained in duplicate. Thank you.
HTML
<div id="items" style="width: 940px; height: 2176px; position: relative;">
<div class="item masonry-brick" style="top: 0px; right: 0px; position: absolute;">
<div class="picture">
<a title="bikini" class="image" href="...-bikini.html">
<img alt="bikini" src="...13508.jpg">
</a>
<div class="item-content">
<h2>bikini</h2>
<div class="item_social">
<ul>
<li><i class="fa fa-eye"></i><span>6</span></li>
<li><i class="fa fa-thumbs-o-up"></i><span>0</span></li>
<li><i class="fa fa-comments"></i><span>0</span></li>
</ul>
</div>
<div class="author-post">
<a class="author" href="....nuong" rel="nofollow">
<img class="author_avatar" alt="nương" src="....ae3c3d8a6a.png">
<span class="author_name">nương</span>
<ul class="author_item">
<li><span>13 giờ trước </span></li>
</ul>
</a>
</div>
</div>
</div>
</div>
//..... more item masonry-brick
</div>
My code C# parsing "but the data obtained in duplicate image and text!",but full item number.
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(htmlPage);
List<Data> datas = new List<Data>();
foreach (var div in htmlDocument.DocumentNode.SelectNodes("//div[starts-with(#class, 'item')]"))
{
Data newdata = new Data();
newdata.Imgsrc = div.SelectSingleNode("//div[#class='picture']//img").Attributes["src"].Value;
newdata.Title = div.SelectSingleNode("//div[#class='item-content']//h2").InnerText.Trim();
newdata.Summary = div.SelectSingleNode("//div[#class='author-post']//span").InnerText.Trim();
datas.Add(newdata);
}
lstDatas.ItemsSource = datas;
Thanks you!
You need to add period/dot (.) at the beginning of your XPath to indicate that the XPath searching scope is local within current div context :
foreach (var div in htmlDocument.DocumentNode.SelectNodes("//div[starts-with(#class, 'item')]"))
{
Data newdata = new Data();
newdata.Imgsrc = div.SelectSingleNode(".//div[#class='picture']//img").Attributes["src"].Value;
newdata.Title = div.SelectSingleNode(".//div[#class='item-content']//h2").InnerText.Trim();
newdata.Summary = div.SelectSingleNode(".//div[#class='author-post']//span").InnerText.Trim();
datas.Add(newdata);
}
Otherwise, the XPath will search within entire HtmlDocument and return the first matched node again and again in every iteration, that's why you got those duplicates.