簡體   English   中英

Laravel-是否可以從外部網站將數據保存到mySQL數據庫?

[英]Laravel - Is it possible to save data to a mySQL database from a external website?

可以說我發現了一個具有以下標記的網站:

 <body> <div id="paper"> <div id="contentwrapper"> <div id="rightcontent"> <h1>1967-002A</h1> <p> <strong>NSSDCA/COSPAR ID:</strong> 1967-002A</p> <div class="twocol"> <div class="urone"> <h2>Description</h2> <p> This US Air Force photo surveillance satellite was launched from Vandenberg AFB aboard a Thor Agena D rocket. It was a KH-4A (Key Hole-4A) type satellite. The satellite had fair image quality. </p> </div> <div class="urtwo"> <h2>Alternate Names</h2> <ul> <li>02642</li> </ul> <h2>Facts in Brief</h2> <p> <strong>Launch Date:</strong> 1967-01-14 <br/> <strong>Launch Vehicle:</strong> Thor <br/> <strong>Launch Site:</strong> Vandenberg AFB, United States <br/> <strong>Mass:</strong> 1500.0 kg <br/> </p> <h2>Funding Agency</h2> <ul> <li>Department of Defense-Department of the Air Force (United States)</li> </ul> <h2>Discipline</h2> <ul> <li>Surveillance and Other Military</li> </ul> </div> </div> </div> </div> </div> </body> 

其中包含信息,例如“說明”,“發射日期”,“發射工具”,“發射地點和質量”,“資助機構和紀律”。 -這些都可能是mySQL數據庫中的列。

該網頁具有/spacecraftDisplay.do?id=1967-002A的鏈接。 我已經有了一個帶有1967-002A的數據庫-航天器標識符。 所以我想從數據庫中獲取每個標識符,並使用相同的標識符保存URL中的數據。 每個網頁都相同

我已經知道如何使用Guzzle從具有JSON格式的外部API保存數據。 我們正在處理外部網站的HTML,而不是JSON。

我首先想知道的是,是否有可能甚至可以從網頁上保存此數據,或者您可以做些什么?

您可以使用DOM解析器http://simplehtmldom.sourceforge.net/

它基本上將整個HTML頁面粘貼在一個對象中,然后您可以訪問該對象中的任何元素。

//Example
$html = file_get_html('http://www.google.com/');
foreach($html->find('img') as $element) {
    echo $element->src . '<br>';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM