工作篇|探讨如何养成亚马逊选品基本功
一键式下载亚马逊商品的五点描述 一键式复制展示权威链接 一键式复制展示亚马逊页面视频链接(附上如何调教ChatGPT话术) 一键式下载亚马逊商品的品牌名、五点描述、排名、ASIN、权威链接 一键式查询亚马逊商品链接下所有变体的关键词排名
留作业:是否可以实现一键式查询亚马逊搜索结果页面下的广告ID和广告ASIN 留作业:是否可以实现一键式下载亚马逊评论并输出分析报告 留作业:是否可以实现一键式下载亚马逊图片 留作业:是否可以实现一键式下载亚马逊QA 留作业:是否可以实现一键式查询亚马逊商品的站外短链和网址
这些留堂作业会在续篇免费分享给读者们,感兴趣的小伙伴们多多动动小手指点赞、转发分享、收藏叭!
基于ChatGpt给出的整合建议实现了运行于Tampermonkey一键式下载亚马逊商品的五点描述的功能插件代码在前文已给出,一并记录此文,点击图文可跳转:
代码如下:
// ==UserScript==
// @name Amazon Scraper
// @namespace http://tampermonkey.net/
// @version 1
// @description Scrape Amazon page bp and download as excel file
// @author lintonghui
// @match https://www.amazon.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const description = Array.from(document.querySelectorAll('#feature-bullets span.a-list-item')).map(span => span.textContent.trim());
console.log(description);
const downloadExcel = (data) => {
const blob = new Blob([data], {type: 'application/vnd.ms-excel'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'amazon_data.xls';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
const downloadButton = document.createElement('button');
downloadButton.innerText = 'Download Excel';
downloadButton.style.position = 'fixed';
downloadButton.style.top = '10px';
downloadButton.style.right = '10px';
downloadButton.addEventListener('click', () => {
const data = [
[ 'Bullet Point'],
...description.map((description) => [description])
].map(row => row.join('\t')).join('\n');
downloadExcel(data);
});
document.body.appendChild(downloadButton);
})();
基于ChatGpt给出的整合建议实现了运行于Tampermonkey一键式复制展示权威链接,演示视频如下:
代码如下:
// ==UserScript==
// @name Find Amazon Canonical Link
// @description 把权威链接添加展示到亚马逊标题节点的上方,且做到可复制Copy
// @version 1
// @author lintonghui
// @match https://*.amazon.com/*
// @match https://*.amazon.co.uk/*
// @match https://*.amazon.co.de/*
// @match https://*.amazon.fr/*
// @match https://*.amazon.it/*
// @match https://*.amazon.es/*
// @match https://*.amazon.co.jp/*
// @match https://*.amazon.com.au/*
// @match https://*.amazon.sg/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Get the canonical link from the HTML code
var link = document.querySelector('link[rel="canonical"]');
var url = link ? link.getAttribute('href') : null;
if (!url) {
console.log('Canonical link not found!');
return;
}
// Create a new container element for the canonical link
var container = document.createElement('div');
container.style.fontWeight = 'bold';
container.style.marginBottom = '20px';
// Add the canonical link to the container element
var linkText = document.createTextNode('canonical link: ');
container.appendChild(linkText);
var linkSpan = document.createElement('span');
linkSpan.style.color = '#C65500';
linkSpan.innerText = url;
container.appendChild(linkSpan);
// Create a new button to copy the canonical link to clipboard
var button = document.createElement('button');
button.style.marginLeft = '10px';
button.innerText = 'Copy';
button.addEventListener('click', function() {
var tempInput = document.createElement('input');
tempInput.value = url;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
button.innerText = 'Copied!';
setTimeout(function() {
button.innerText = 'Copy';
}, 1000);
});
container.appendChild(button);
// Get the page title element
var title = document.getElementById('productTitle');
// Insert the container element before the page title
if (title) {
title.parentNode.insertBefore(container, title);
} else {
console.log('Product title not found!');
}
})();
基于ChatGpt给出的整合建议实现了运行于Tampermonkey一键式复制展示权威链接,演示视频如下:
// ==UserScript==
// @name Amazon 480p MP4 Link Crawler and Exporter
// @namespace amazon-480p-mp4-link-crawler-exporter
// @version 1
// @description Crawl all 480p MP4 links on an Amazon product source page and display them on the page, with an option to export to Excel spreadsheet format (XLS) via a download button above the title. Note: The download button will be hidden if there are no 480p MP4 links found on the page.
// @author lintonghui
// @match https://*.amazon.com/*
// @match https://*.amazon.co.uk/*
// @match https://*.amazon.co.de/*
// @match https://*.amazon.fr/*
// @match https://*.amazon.it/*
// @match https://*.amazon.es/*
// @match https://*.amazon.co.jp/*
// @match https://*.amazon.com.au/*
// @match https://*.amazon.sg/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const videoLinks = [];
const source = document.documentElement.innerHTML;
const regex = /"url":"([^"]+\.480\.mp4[^"]*)"/g;
let match;
while ((match = regex.exec(source)) !== null) {
videoLinks.push(match[1]);
}
if (videoLinks.length > 0) {
// Create div to hold links and download button
const containerDiv = document.createElement('div');
containerDiv.style.display = 'flex';
containerDiv.style.alignItems = 'center';
containerDiv.style.justifyContent = 'space-between';
containerDiv.style.position = 'fixed';
containerDiv.style.top = '50px';
containerDiv.style.left = '50%';
containerDiv.style.transform = 'translateX(-50%)';
containerDiv.style.background = 'white';
containerDiv.style.padding = '10px';
containerDiv.style.borderRadius = '5px';
containerDiv.style.boxShadow = '0 2px 6px rgba(0,0,0,0.2)';
// Create div to hold links
const linkDiv = document.createElement('div');
linkDiv.innerHTML = '<h3>Amazon 480p MP4 Links:</h3><ul>' +
videoLinks.map(link => `<li><a href="${link}">${link}</a></li>`).join('') +
'</ul>';
containerDiv.appendChild(linkDiv);
// Create download button
const downloadButton = document.createElement('button');
downloadButton.innerText = 'Download as Excel Spreadsheet';
downloadButton.style.backgroundColor = '#f0c14b';
downloadButton.style.border = '1px solid #a88734';
downloadButton.style.borderRadius = '3px';
downloadButton.style.color = '#111';
downloadButton.style.fontWeight = 'bold';
downloadButton.style.cursor = 'pointer';
downloadButton.style.padding = '5px 10px';
downloadButton.style.marginLeft = '10px';
downloadButton.addEventListener('click', function() {
const filename = 'amazon-480p-mp4-links.xls';
const csvHeaders = ['Link'];
const csvData = videoLinks.map(link => [link]);
let csv = csvHeaders.join(',') + '\n';
csv += csvData.map(row => row.join(',')).join('\n');
const blob = new Blob([csv], {type: 'application/vnd.ms-excel'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
setTimeout(() => {
URL.revokeObjectURL(url);
}, 0);
});
// Add download button to container div
containerDiv.appendChild(downloadButton);
// Add container div to page
document.body.insertBefore(containerDiv, document.body.firstChild);
}
})();
为了让读者们更直观的明白如何调教ChatGpt,附上调教的指令,如下:
02 说出你想要让ChatGpt继续补充修改的需求
03 运行代码检验成果
一键式下载亚马逊商品的内容信息,包括亚马逊商品的品牌名、五点描述、排名、ASIN、权威链接,演示视频如下:
代码如下:
// ==UserScript==
// @name Extract Product Data and Export to Excel
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Extract product data from Amazon page and export to Excel using Tampermonkey script (without XLSX or XLSX.utils)
// @author lintonghui
// @match https://*.amazon.com/*
// @match https://*.amazon.co.uk/*
// @match https://*.amazon.co.de/*
// @match https://*.amazon.fr/*
// @match https://*.amazon.it/*
// @match https://*.amazon.es/*
// @match https://*.amazon.co.jp/*
// @match https://*.amazon.com.au/*
// @match https://*.amazon.sg/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 获取产品标题内容
const productTitle = document.getElementById("productTitle").innerText.trim();
// 获取功能列表内容
const featureBullets = document.getElementById("feature-bullets");
const featureList = featureBullets.querySelectorAll("ul.a-unordered-list > li > span.a-list-item");
const features = Array.from(featureList).map(item => item.innerText.trim());
// 获取排行榜信息
const rankList = document.querySelector("ul.zg_hrsr > li > span.a-list-item");
const rankInfo = rankList ? rankList.innerText.trim() : "";
// 获取品牌名称、ASIN和canonical链接
const brandInfo = document.querySelector("div#bylineInfo > .a-link-normal");
const brandName = brandInfo ? brandInfo.innerText.trim() : "";
const asinInfo = document.querySelector('input[name="ASIN"]');
const asin = asinInfo ? asinInfo.value : "";
const canonicalLink = document.querySelector('link[rel="canonical"]');
const canonicalUrl = canonicalLink ? canonicalLink.href : "";
// 创建一个按钮元素
const exportBtn = document.createElement("button");
exportBtn.textContent = "Export to Excel";
exportBtn.style.padding = "5px 10px";
exportBtn.style.margin = "10px";
// 将按钮添加到页面中,并绑定点击事件处理程序
document.body.prepend(exportBtn);
exportBtn.addEventListener("click", () => {
// 创建一个CSV格式的数据字符串
const csvData = `"Product Title","Features","Ranking Info","Brand Name","ASIN","CanonicalUrl"\n"${productTitle}","${features.join(",")}","${rankInfo}","${brandName}","${asin}","${canonicalUrl}"`;
// 创建一个<a>元素,设置下载属性并模拟点击
const downloadLink = document.createElement("a");
downloadLink.download = "product_data.csv";
downloadLink.href = `data:text/csv;charset=utf-8,${encodeURIComponent(csvData)}`;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
});
})();
基于上方的代码如果想要继续实现批量ASIN下载信息呢?
// ==UserScript==
// @name Export to Excel
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Extract product data from Amazon search page and export to Excel using Tampermonkey script (without XLSX or XLSX.utils)
// @author lingtonghui
// @match https://*.amazon.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 判断当前是否为搜索结果页面
if (!window.location.href.includes("/s?k=") && !window.location.href.includes("/bestsellers")) {
return;
}
// 获取所有包含ASIN的链接元素
const asinLinks = document.querySelectorAll("a[href*='/dp/'], a[href*='/product/'], a[href*='/gp/product/']");
// 创建一个按钮元素
const exportBtn = document.createElement("button");
exportBtn.textContent = "Export to Excel";
exportBtn.style.padding = "5px 10px";
exportBtn.style.margin = "10px";
// 将按钮添加到页面中,并绑定点击事件处理程序
const resultsArea = document.getElementById("a-page");
resultsArea.parentNode.insertBefore(exportBtn, resultsArea);
exportBtn.addEventListener("click", () => {
const dataRows = [];
// 遍历所有包含ASIN的链接元素
asinLinks.forEach(link => {
// 获取ASIN和canonical链接
const asin = link.href.match(/\/(dp|product)\/([A-Z0-9]+)/)[2];
const canonicalUrl = link.href;
// 获取品牌名称、功能列表、产品标题和排行榜信息
const productSection = link.closest("div[data-asin]");
const brandInfo = productSection.querySelector("div#bylineInfo > .a-link-normal");
const brandName = brandInfo ? brandInfo.innerText.trim() : "";
const featureBullets = productSection.querySelector("div#feature-bullets");
const featureList = featureBullets ? featureBullets.querySelectorAll("ul.a-unordered-list > li > span.a-list-item") : [];
const features = Array.from(featureList).map(item => item.innerText.trim());
const productTitle = productSection.querySelector("h2 > a > span").innerText.trim();
const rankList = productSection.querySelector("span.zg-badge-text");
const rankInfo = rankList ? rankList.innerText.trim() : "";
// 将数据行添加到数组中
dataRows.push([brandName, asin, canonicalUrl, features.join(", "), productTitle, rankInfo]);
});
// 创建一个CSV格式的数据字符串
const csvData = `"Brand Name","ASIN","CanonicalUrl","Features","Product Title","Ranking Info"\n${dataRows.map(row => `"${row.join('","')}"`).join("\n")}`;
// 创建一个<a>元素,设置下载属性并模拟点击
const downloadLink = document.createElement("a");
downloadLink.download = "product_data.csv";
downloadLink.href = `data:text/csv;charset=utf-8,${encodeURIComponent(csvData)}`;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
});
})();
输入关键词可一键式查询链接下所有变体的亚马逊商品关键词排名,演示视频如下:
// ==UserScript==
// @name Amazon Keyword Rank Tracker UP!
// @namespace http://tampermonkey.net/
// @version 1
// @description Track the realtime rank of keywords on Amazon product search 7page
// @author lintonghui
// @match https://*.amazon.com/*
// @match https://*.amazon.co.uk/*
// @match https://*.amazon.co.de/*
// @match https://*.amazon.fr/*
// @match https://*.amazon.it/*
// @match https://*.amazon.es/*
// @match https://*.amazon.co.jp/*
// @match https://*.amazon.com.au/*
// @match https://*.amazon.sg/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
function getSearchPage(keywords, pageNumber, callback) {
GM_xmlhttpRequest({
method: "GET",
url: `https://www.amazon.com/s?k=${encodeURIComponent(keywords)}&page=${pageNumber}`,
onload: function(response) {
callback(response.responseText);
}
});
}
function checkProductRankInPage(html, asin) {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const searchResults = doc.querySelectorAll('.s-result-item');
for (let i = 0; i < searchResults.length; i++) {
if (searchResults[i].getAttribute('data-asin') === asin) {
return i + 1;
}
}
return -1;
}
function createResultTable() {
const table = document.createElement('table');
table.style.borderCollapse = 'collapse';
table.innerHTML = `
<thead style="display: none;">
<tr>
<th style="border: 1px solid black; padding: 5px;">Keyword</th>
<th style="border: 1px solid black; padding: 5px;">Page</th>
<th style="border: 1px solid black; padding: 5px;">Rank</th>
</tr>
</thead>
<tbody></tbody>
`;
return table;
}
function addResultToTable(table, keyword, page, rank) {
const row = document.createElement('tr');
row.innerHTML = `
<td style="border: 1px solid black; padding: 5px;">${keyword}</td>
<td style="border: 1px solid black; padding: 5px;">${page}</td>
<td style="border: 1px solid black; padding: 5px;">${rank}</td>
`;
table.querySelector('tbody').appendChild(row);
table.querySelector('thead').style.display = 'table-header-group';
}
function clearResults(table) {
table.querySelector('tbody').innerHTML = '';
table.querySelector('thead').style.display = 'none';
}
function trackKeywordRank(keywordsArray, asinList, maxPages) {
const table = createResultTable();
const titleElement = document.querySelector('#titleSection');
titleElement.parentNode.insertBefore(table, titleElement);
keywordsArray.forEach((keywords) => {
for (let i = 1; i <= maxPages; i++) {
getSearchPage(keywords, i, function(html) {
let rankFound = false;
for (let j = 0; j < asinList.length; j++) {
const rank = checkProductRankInPage(html, asinList[j]);
if (rank !== -1) {
addResultToTable(table, keywords, i, rank);
rankFound = true;
}
}
if (!rankFound) {
addResultToTable(table, keywords, i, 'Not found');
}
});
}
});
}
function createKeywordInput() {
const container = document.createElement('div');
container.innerHTML = `
<label for="keywordInput">Enter keywords (separated by ";"):</label>
<input type="text" id="keywordInput" style="margin-left: 10px;">
<button id="searchButton" style="margin-left: 10px;">Search</button>
`;
return container;
}
const asinRegex = /\/dp\/([A-Z0-9]{10})\//;
const asinMatch = window.location.href.match(asinRegex);
if (asinMatch) {
const asin = asinMatch[1];
// Create keyword input and button
const keywordInputContainer = createKeywordInput();
const titleElement = document.querySelector('#titleSection');
titleElement.parentNode.insertBefore(keywordInputContainer, titleElement);
// Create empty result table
const table = createResultTable();
titleElement.parentNode.insertBefore(table, titleElement);
// Add click event listener to the search button
const searchButton = document.querySelector('#searchButton');
searchButton.addEventListener('click', function() {
const keywords = document.querySelector('#keywordInput').value;
if (keywords) {
// Clear existing results
clearResults(table);
// Split keywords by ";"
const keywordsArray = keywords.split(';').map(keyword => keyword.trim());
// Extract ASIN variations
const asinVariations = Array.from(document.querySelectorAll('#variation_color_name li'))
.map(variation => variation.getAttribute('data-defaultasin'));
// Add parent ASIN to variations
asinVariations.unshift(asin);
// Track keyword ranks for all ASIN variations
trackKeywordRank(keywordsArray, asinVariations, 7);
}
});
}
})();
---优质广告合作服务商伙伴--
---持续招募优质广告合作服务商伙伴--
喜欢此内容的人还喜欢:
写给每一位追梦的人
排版丨林子酱
文案丨林子酱
摄像丨林子酱
我明白你会来,所以我等
完