Use YQL to resolve the front-end crawl page and resolve

Source: Internet
Author: User

When writing code today, in order to save back-end performance, you want to use a front-end browser to crawl a page and parse out some of the content.

Because cross-domain is involved, it is necessary to use the JSONP, but JSONP need to return JSON format, and we need to crawl the content of a Web page, so the direct use of JSONP will be an error. So we need to use YQL to help us parse the HTML content into JSON format.

1 $.ajax ({  2    URL: "HTTP://QUERY.YAHOOAPIS.COM/V1/PUBLIC/YQL" 3  , type: ' Jsonp ' ) 4  , data: {  5    Q: "SELECT * from HTML where url=\" Http://www.baidu.com/\ "",  6< /c11>    format: "JSON" 7   }  8  , Success:  (resp) + = { 9    Console.log (resp)   });

The URL is fixed, the address for the YQL service, and format is the one you want to parse. Q is the YQL statement, where HTML is the pre-conversion format.

Use YQL to resolve the front-end crawl page and resolve

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.