0
나는 simple_html_dom이 작동하는 방법을 이해하려고 노력하고 특정 범주의 일부 데이터를 가져옵니다. 그래서 몇 가지 테스트를 할 수있는 wp 사이트를 만들었습니다.간단한 HTML 돔 파서 문제
// Create DOM from URL
$html = file_get_html('http://localhost/mydemosite/category/sports/');
// Find all article blocks
foreach($html->find('div.article') as $article) {
$item['title'] = $article->find('div.post-title', 0)->plaintext;
$item['thumb'] = $article->find('div.post-thumbnail', 0)->plaintext;
$item['details'] = $article->find('div.entry', 0)->plaintext;
$articles[] = $item;
}
print_r($articles);
내가 오류가있어이를 실행하고 있습니다 : 라인 28
Notice: Undefined variable: articles in C:\xampp\htdocs\mydemosite\test.php on line 28
이 print_r($articles);
입니다
내가 맞게 약간의 수정을 공식 웹 사이트의 코드를 가져다가 한 내 조직은 :
<article class="item-list item_1">
<h2 class="post-title"><a href="http://localhost/mydemosite/category/sports/demo-post" title="mydemo post" rel="bookmark">my demo post 1</a></h2>
<p class="post-meta">
<span class="tie-date">2 mins ago</span>
<span class="post-comments">
<a href="http://localhost/mydemosite/category/sports/demo-post/#disqus_thread" title="my demo post 1" data-disqus-identifier="1 http://localhost/mydemosite/category/sports/?p=1"></a></span>
</p>
<div class="post-thumbnail">
<a href="http://localhost/mydemosite/category/sports/demo-post/" title="my demo post 1" rel="bookmark">
<img width="300" height="160" src="http://localhost/mydemosite/wp-content/uploads/demo-post-300x160.jpg" class="attachment-tie-large wp-post-image" alt="my demo post 1">
</a>
</div>
<!-- post-thumbnail /-->
<div class="entry">
<p>Hello world... this is a demo post description, so if you want to read more...</p>
<a class="more-link" href="http://localhost/mydemosite/category/sports/demo-post">Read More »</a>
</div>
<div class="clear"></div>
</article>
그것은 작동하지 않습니다 ... 것은 내가 그것을 실행하고 때 나는 흰색 화면을 가지고 : 내가 그것을 발견 좋아 배열() –
을 ...하지만 내 다른 문제는 IMG SRC는 내부 얻는 방법이다