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