我想知道如何從網站使用PHP刮掉源代碼的內容。我曾嘗試使用http://simplehtmldom.sourceforge.net/,也看着How do you parse and process HTML/XML in PHP?我仍然很難從源代碼獲取信息。正如你所看到的,源代碼的主頁面包含作者的鏈接列表,其中包括年份和寫入的書籍數量。PHP:如何從網站源頁面提取內容或抓取數據集
<div id="fleft">
<ul>
<li><a href="http://www.books.com/john-smith/index.html">John Smith (2011-2012)</a> : 11 books
<li><a href="http://www.books.com/bobby-bob/index.html">Bobby Bob (2011-2012)</a> : 89 books
....
</ul>
</div>
我點擊約翰史密斯它會打開約翰史密斯寫的書籍列表。
<h1>John Smith (11 Books)</h1>
<div id="fleft">
<ul>
<li><a href="http://www.books.com/john-smith/best-book.html">Best Book</a>
<li><a href="http://www.books.com/john-smith/other-best-book.html">Other Best Book</a>
....
</ul>
</div>
我點擊書「最好的書」之一,它會顯示書的標題和aurther和本書的整個故事。
<div id="bookbox">
<h1>Book : Best Book</h1>
<h2>Aurther : John Smith</h2>
<pre>
story of the best book......
.......
....
the end
</pre>
我希望能夠抓住所有的作者姓名,他們的年份,書籍列表以及書籍內容。實際上就是數據集。有人可以幫助我或向我展示php的代碼示例以實現此目的。我想創建一個所有作者姓名,年份,他們創建的書籍,書籍標題,類別,書籍內容等信息的數據庫。
有大量的資源可以找到;嘗試「PHP屏幕刮」 –
@Jonathan Spooner你能給我一個這種情況的例子=) – merrill
你可以告訴我們你的代碼與simplehtmldom,所以我們可以看到它爲什麼不工作 – bumperbox