The fastest way to capture web data and insert a database with JS

Source: Internet
Author: User

Today to teach you a quick way to collect data from the site, because it is too late, directly on the example, here to collect easy Car network product data for example.

Idea: Using JS to get Web page data and generate SQL command, execute SQL command to insert the collected data into the database.

1. Open the website with Google Chrome or Firefox: http://car.bitauto.com/(Brand Daquan), http://car.bitauto.com/audi/(model Encyclopedia)

2. Press F12 to enter debug mode, select Console and type the following code

//JavaScript Document(function() {  varHM = document.createelement ("Script"); HM.SRC= "Http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"; vars = document.getelementsbytagname ("script") [0]; S.parentnode.insertbefore (hm, s);}) (); SetTimeout (function() {$.ajaxsettings.async=false; //var data = [];    varsql = ' ';$(". List_pic li"). each (function(index, Element) {varBrand ={url: $ ( This). Find ("A:eq (1)"). attr (' href '), name:$ ( This). Find ("A:eq (1)"). Text (), cars:[]}; SQL+ = "INSERT into ' Dp_jgcrm_brand ' (pid,title) VALUES (' 0 ', '" +$ ( This). Find ("A:eq (1)"). Text () + "\ r \ n Set @pid = last_insert_id (); \ r \ n"; $.get (Brand.url,function(HTML) {$ (HTML). Find (". Cartype-section. P-list. Name a"). each (function(index, Element) {SQL+ = "INSERT into ' Dp_jgcrm_brand ' (pid,title) VALUES (@pid, '" +$ ( This). Text () + "'); \ r \ n"; Brand.cars.push ($ ( This). text ());    });        }); //Data.push (brand);});//console.log (data);console.log (SQL)},2000)

3. Copy SQL commands and the rest of you should know.

The difficulty of learning procedure is the thought and the method, the language is only the tool, if you are willing to study together with me, may add my: fafa2088

For SE: Automotive data dictionary, car acquisition

The fastest way to capture web data and insert a database with JS

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.