Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Skrypt pobierający odnośnik ze strony i zamieniający go
Kostekk
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 21.08.2008

Ostrzeżenie: (0%)
-----


Jest to mój pierwszy post na tym forum, więc się przywitam: Cześć.

Chcę zrobić skrypt, który będzie brał ze strony X wszystkie odnośniki zaczynające się od http://y/, zmieniał w nim kawałek linka (np. adres z y na z), a potem zwracał go zmienionego.
Tyle, że wiem tylko jak zamienić tekst (str_replace), a nie wiem jak zrobić to pobieranie linków.
No i zwracam się z prośbą do Was, czy ktoś mógłby mi pomóc i napisać chociaż jakiś szablon, który by pobierał linki? Zobaczę jak działa i pozmieniam to co mi potrzebne.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
elemek
post
Post #2





Grupa: Zarejestrowani
Postów: 71
Pomógł: 24
Dołączył: 14.08.2008

Ostrzeżenie: (0%)
-----


wyciaganie linkow ze strony:

  1. <?php
  2. error_reporting(E_STRICT | E_ALL);
  3. /**
  4.  * Tool for downloading files and fetching HTML contents for given URL.
  5.  * @author Marcin Malinowski /ElemeK
  6.  * @copyright 2008
  7.  * @version 1.0.3.17 (skrócona)
  8.  *
  9.  */
  10. class CurlTool {
  11.  
  12. /*
  13.  * Default options, feel free to alter them and add new before calling main func
    tions.
  14.  */
  15. public static $options = array(
  16. CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0',
  17. CURLOPT_AUTOREFERER => true,
  18. CURLOPT_COOKIEFILE => '',
  19. CURLOPT_FOLLOWLOCATION => true
  20. );
  21.  
  22. /**
  23.  * Use this function to download web page internal HTML.
  24.  * @param string $url web page url.
  25.  * @param boolean $verbose status messages are displayed when this is set to tru
    e.
  26.  * @return string web page internal HTML.
  27.  */
  28. public static function fetchContent($url, $verbose = false) {
  29. if (($curl = curl_init($url)) == false) {
  30. throw new Exception("curl_init error for url $url.");
  31. }
  32.  
  33. if ($verbose === true) {
  34. echo "Reading $url ... ";
  35. }
  36.  
  37. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  38. curl_setopt_array($curl, self::$options);
  39.  
  40. $content = curl_exec($curl);
  41. if ($content === false) {
  42. throw new Exception("curl_exec error for url $url.");
  43. }
  44.  
  45. curl_close($curl);
  46. if ($verbose === true) {
  47. echo "Done.\n";
  48. }
  49.  
  50. return $content;
  51. }
  52. }
  53.  
  54. '#href="(http://www.onet.pl/.+?)"#i',
  55. CurlTool::fetchContent('http://www.onet.pl'),
  56. $linki,
  57. PREG_SET_ORDER
  58. );
  59.  
  60. print_r($linki);
  61. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.10.2025 - 19:00