It's also boring! Use vue to output random search keyword images of Site B

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.