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