It's also boring! Use vue to output the random search keyword image of Site B at http://ciyuanai.net/icon/#so far ~ These images can be viewed on site B every day, which is interesting 233
I originally wanted to write nodejs crawlers to download these images, but the elements on the page captured through cheerio always prompt undefined and read the webpage source code !! There is no such thing. let's take a look at the Network. Aha! It was originally output in json!
I thought about how to output data directly using Vue, a v-for task! However, I used ajaxGet and found that the cross-origin was used. I wanted to use jsonp, CORS or other solutions, but the implementation seemed quite troublesome, so I used php curl here (haha! Artifacts)
Use curl_init in php to obtain webpage content:
$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_ENCODING, "application/json"); // add this setting to json encoding; otherwise, garbled code is returned; curl_setopt ($ ch, CURLOPT_TIMEOUT, 60 ); $ json = curl_exec ($ ch); curl_close ($ ch); print_r ($ json );
Okay! Cross-domain problem solved ~
You can directly use $. getJSON of jq or $. ajax to directly obtain the data returned by php. here I use vue-resource and then use v-for to output the data to the page cyclically! The page here uses the flex layout, which is very powerful!