• Resolved salvatorericcardi

    (@richdeveloper)


    Hi,
    I’ve a problem with the WordPress API in the subject. I posted the code below: this returns blank page, instead it should return an HTTP Response or a WP_Error, but nothing. Why?

    <?php
    
    class The_Crawler {
    
        public function __construct() { }
    
        public function get_classifieds( $urls ) {
    
            foreach($urls as $url) {
    
                $response = wp_remote_get( $url );
    
                print_r($response);
    
                if ( is_array( $response ) && ! is_wp_error( $response ) ) {
                    $body = wp_remote_retrieve_body( $response ); 
    
                    $pattern = '<h3\sclass="title">.*</h3>';
                    preg_match( $pattern, $body, $titles );
                    print_r( $titles );
                }
    
            }
    
        }
    
    }
    
    $urls = [
        'https://www.kijiji.it/motori/moto-e-scooter/'
    ];
    
    The_Crawler::get_classifieds( $urls );

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem with HTTP API’ is closed to new replies.