【问题标题】:Multiple URL from list used in CURLCURL 中使用的列表中的多个 URL
【发布时间】:2019-06-03 17:20:20
【问题描述】:

我已经创建了这个脚本:

<?php
    
            
        </head>
    
    <form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <fieldset>
    
    
    <legend>Linki</legend>
    
    
    <div class="form-group">
      <label class="col-md-4 control-label" for="textarea">Linki</label>
      <div class="col-md-4">                     
        <textarea class="form-control" id="textarea" name="name">kazdy link w osobnej linijce </textarea>
      </div>
    </div>
    
    
    <div class="form-group">
      <label class="col-md-4 control-label" for="wyslij"></label>
      <div class="col-md-4">
        <button id="wyslij" name="wyslij" class="btn btn-default">Button</button>
      </div>
    </div>
    
    </fieldset>
    </form>
    
    
    
    
    
    <table>
    <?
    for ($i = 0; $i <= $count; $i++) {
    echo "<tr><td>".$lista[$i]."</td></tr>";
    }
    ?>
    </table>
    </html>

它并没有像我预期的那样工作。

当我在表单中输入 url 时,它会通过爆炸将其剪切,并且每个 url 都设置为新的列表元素。

例如网址:

google.com 
yahoo.com 
ebay.com

创造

lista[0] -> google.com 
lista[1] -> yahoo.com 
lista[2] -> ebay.com

现在我想使用$html = "file_get_contents_curl($lista[$i]);" 中列表中的每个网址来抓取og:image

但它不起作用。 当我在表单中只使用一个 url 时,它会从监听的 url 创建到 og:image 的结果 url。当表单中有多个 url 时,结果只显示表单中的 url。

例如它应该如何工作:

表单中的网址:

https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400

返回:

https://i.ebayimg.com/images/i/292593246536-0-1/s-l1000.jpg

表单中的网址:

https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400
https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400

应该返回:

https://i.ebayimg.com/images/i/292593246536-0-1/s-l1000.jpg
https://i.ebayimg.com/images/i/292593246536-0-1/s-l1000.jpg

但它会返回:

https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400
https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400

如何改变它。我是 php 新手,并在几个小时内从互联网上的其他脚本创建了此代码。

【问题讨论】:

  • 不要指望它能解决你的问题,但它应该是for ($i=0; $i&lt;$count; $i++)(而不是$i&lt;=$count)。如果有 3 个 URL,它们将具有索引 0、1、2,因此您的循环需要在到达 3 之前停止。

标签: php list curl dom


【解决方案1】:

for ($i=0; $i&lt;=$count; $i++) 应该是 for ($i=0; $i&lt;$count; $i++)curl_close($ch); 应该在 file_get_contents_curl 中调用。您确认og:image 存在于这三个网站中吗?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-05-30
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多