doukun0888 2017-09-25 19:24
浏览 55
已采纳

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

Lets say I found a website that has the following markup:

<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>

This contains information, such as Description, Launch Date, Launch Vehicle, Launch Site and Mass, Funding Agency and Discipline. - These could all be the columns in the mySQL database.

The webpage has a link of /spacecraftDisplay.do?id=1967-002A. I already have a database with the 1967-002A - the spacecraft identifier. So I am guessing to take each identifier from my database and save the data from the URL with the same identifier. Each webpage is the same

I already know how to save data from an external API which has a JSON format using Guzzle. Instead of JSON, we are dealing with the HTML of the external website.

What I want to know first, if its possible to even save this data from the webpage or is there limitations to what you can do?

</div>
  • 写回答

1条回答 默认 最新

  • dsigg21445 2017-09-25 19:28
    关注

    You can go with a DOM parser http://simplehtmldom.sourceforge.net/

    It basically sticks an entire HTML page in an object then you can access any element from that object.

    //Example
    $html = file_get_html('http://www.google.com/');
    foreach($html->find('img') as $element) {
        echo $element->src . '<br>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流