|
/* |
|
Usage: |
|
|
|
1. Paste contents from export step to https://shancarter.github.io/mr-data-converter/ |
|
2. Replace fields with that output |
|
3. Replace selector manually. Optional. |
|
4. Paste this code in scraper console |
|
5. Hit enter |
|
6. All fields should be populated, save it as a preset |
|
|
|
Note if data converter goes offline use: |
|
https://web.archive.org/web/20180628080610/https://shancarter.github.io/mr-data-converter/ |
|
*/ |
|
|
|
|
|
// Data |
|
selector = '//*[@id="content"]/div[2]/div[2]/div[2]/div/ul/li/article' |
|
|
|
// Convert excel to JS with https://shancarter.github.io/mr-data-converter/ |
|
// Or use papa parse https://www.papaparse.com/ |
|
fields=[ |
|
["tags","./section[1]/div/div/span[1]/text()[2]"], |
|
["title","./section[2]/div/h3/a"], |
|
["URL","./section[2]/div/h3/a/@href"], |
|
["author","./section[2]/div/div/a"], |
|
["author URL","./section[2]/div/div/a/@href"], |
|
["type","./section[2]/div/span"], |
|
["feat1","./section[4]/ul/li[1]"], |
|
["feat2","./section[4]/ul/li[2]"], |
|
["feat3","./section[4]/ul/li[3]"], |
|
["price","./section[3]/span[1]/div"], |
|
["rating","./section[3]/span[2]/div/div/@aria-label"], |
|
["reviews","./section[3]/span[2]/div/span/text()[2]"], |
|
["sales","./section[3]/span[3]/span/text()[1]"], |
|
["updated","./section[3]/span[4]/text()[2]"] |
|
] |
|
// Data END |
|
|
|
// Helpers |
|
addField = function(field){ |
|
a=$('#options-attributes > tbody > tr:last > td:nth-child(4) > a:nth-child(2)') |
|
name = field[0] |
|
xpath = field[1] |
|
a.click() |
|
x=$('#options-attributes > tbody > tr:last input[name="attributes[][xpath]"]') |
|
n=$('#options-attributes > tbody > tr:last input[name="attributes[][name]"]') |
|
|
|
x.val(xpath) |
|
n.val(name) |
|
} |
|
// Helpers END |
|
|
|
// Clean state |
|
// Better reload with CTRL + R |
|
// dels = $('#options-attributes > tbody > tr > td:nth-child(4) > a:nth-child(1)') |
|
// dels.click() |
|
// Clean state END |
|
|
|
// Import |
|
$('input[name="selector"]').val(selector) |
|
for (var i = 0; i < fields.length; i++) { addField(fields[i]) } |
|
// Import END |
|
|
|
// Remove first button |
|
del = $('#options-attributes > tbody > tr:nth-child(1) > td:nth-child(4) > a:nth-child(1)') |
|
del.click() |
|
// Remove first button END |