gpt4 book ai didi

php - Laravel - 是否可以将数据从外部网站保存到 mySQL 数据库?

转载 作者:行者123 更新时间:2023-11-29 10:36:03 25 4
gpt4 key购买 nike

假设我发现了一个具有以下标记的网站:

<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>';
}

关于php - Laravel - 是否可以将数据从外部网站保存到 mySQL 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46412718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com