第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 url 中放置一個不斷變化的值?

如何在 url 中放置一個不斷變化的值?

PHP
繁星淼淼 2022-01-02 15:37:17
目前我有一個 curl 腳本可以從這個 url 中抓取信息。$url = 'https://www.marktplaats.nl' . '/q/iphone/p/1/#offeredSince:Gisteren/';是否可以從更多鏈接中自動抓取信息?例如,當(dāng)我將一些變量設(shè)置為 5 等時,還要同時抓取第 2、3、4、5 頁等。https://www.marktplaats.nl/q/iphone/p/1/#offeredSince:Gisteren/https://www.marktplaats.nl/q/iphone/p/2/#offeredSince:Gisteren/https://www.marktplaats.nl/q/iphone/p/3/#offeredSince:Gisteren/https://www.marktplaats.nl/q/iphone/p/4/#offeredSince:Gisteren/https://www.marktplaats.nl/q/iphone/p/5/#offeredSince:Gisteren/我的 cURL 腳本支持抓取 1 個 url。但不是多個。declare(strict_types = 1);set_time_limit(0);ob_start();include 'functions.php';$curl = curl_init();$url = 'https://www.marktplaats.nl' . '/q/iphone/p/1/#offeredSince:Gisteren/';curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($curl);$advertisements = array();preg_match_all('\/a\/.*?.*?.html', $result, $links);$advertisements = $links[0];我想要一個“選項”,讓我通過為頁碼設(shè)置可變值來抓取多個鏈接。在我弄清楚之前編輯:這是我目前的代碼。我是否需要為此使用 curl_multi_init,然后它是如何工作的?<?php declare(strict_types = 1);set_time_limit(0);ob_start();include 'functions.php';$curl = curl_init();$url = 'https://www.marktplaats.nl' . '/q/laptoptas/p/18/#offeredSince:Gisteren/';curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($curl);$advertisements = array();// regex for advertisement linkspreg_match_all('%\/a\/.*?.*?.html%', $result, $links);$advertisements = $links[0];// encode the array into a JSON string$encodedString = json_encode($advertisements, JSON_PRETTY_PRINT);$decodedArray = json_decode($encodedString, true);$decodedArray = array_values(array_unique($decodedArray, SORT_REGULAR));$content = null;foreach($decodedArray as $link) {    $content .= "https://marktplaats.nl" . $link . PHP_EOL;}file_put_contents('advertisements.txt', $content, FILE_APPEND);$bestand = file('advertisements.txt');$bestand = array_unique($bestand);file_put_contents('advertisements.txt', $bestand);在我想通之后編輯:好吧,正如你所讀到的。我想到了。感謝 l'L'l,為我提供了正確的循環(huán)!
查看完整描述

1 回答

?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗 獲得超7個贊

一個簡單的for loop應(yīng)該工作:


for ($i = 1; $i <= 5; $i++) {

    $url = 'https://www.marktplaats.nl' . '/q/iphone/p/' . $i . '/#offeredSince:Gisteren/';

    ...

}


? https://www.php.net/manual/en/control-structures.for.php


查看完整回答
反對 回復(fù) 2022-01-02
  • 1 回答
  • 0 關(guān)注
  • 219 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號