工作篇|探讨如何养成亚马逊选品基本功
实现一键式查询亚马逊搜索结果页面下的广告ID和广告ASIN
// ==UserScript==
// @name Amazon AdID and ASIN Extractor
// @namespace https://www.example.com/
// @version 1.0
// @description Extract adId and ASIN from Amazon search results for sponsored products and export to Excel spreadsheet with product title information.
// @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_download
// ==/UserScript==
(function() {
'use strict';
// 创建一个表格来存储 adId 和 ASIN
const table = document.createElement('table');
table.style.position = 'sticky';
table.style.top = '0';
table.style.background = '#fff';
table.style.zIndex = '1000';
table.border = '1';
const tr = document.createElement('tr');
const th1 = document.createElement('th');
const th2 = document.createElement('th');
const th3 = document.createElement('th');
th1.textContent = 'Title';
th2.textContent = 'AdId';
th3.textContent = 'ASIN';
tr.appendChild(th1);
tr.appendChild(th2);
tr.appendChild(th3);
table.appendChild(tr);
// 添加下载按钮
const downloadBtn = document.createElement('button');
downloadBtn.textContent = 'Download as CSV';
downloadBtn.style.position = 'sticky';
downloadBtn.style.top = '0';
downloadBtn.style.marginLeft = '10px';
downloadBtn.style.zIndex = '1000';
downloadBtn.addEventListener('click', function() {
downloadTableAsCSV(table, 'Amazon_AdId_Extractor');
});
// 下载表格为CSV文件的函数
function downloadTableAsCSV(table, filename) {
let csvContent = '';
const rows = table.querySelectorAll('tr');
rows.forEach(row => {
const cols = row.querySelectorAll('td, th');
cols.forEach((col, index) => {
let cellText = col.textContent;
if (cellText.includes('"')) {
cellText = cellText.replace(/"/g, '""');
}
if (cellText.includes(',') || cellText.includes('"')) {
cellText = '"' + cellText + '"';
}
csvContent += cellText;
if (index < cols.length - 1) {
csvContent += ',';
}
});
csvContent += '\r\n';
});
const csvBlob = new Blob([csvContent], {type: 'text/csv;charset=utf-8'});
const csvURL = URL.createObjectURL(csvBlob);
GM_download({
url: csvURL,
name: filename + '.csv',
onload: function() {
URL.revokeObjectURL(csvURL);
}
});
}
// 获取所有 sponsored product 的父元素
const sponsoredProducts = document.querySelectorAll('.s-result-item[data-component-type="s-search-result"]');
// 遍历每个 sponsored product,并添加 adId 和 ASIN
sponsoredProducts.forEach(product => {
// 获取 href 属性值
const href = product.querySelector('a.a-link-normal').getAttribute('href');
if (href && href.includes('adId=')) {
// 从 href 中提取 adId
const adId = href.match(/adId=([^&]+)/);
if (adId && adId.length > 1) {
// 获取产品标题
const titleElement = product.querySelector('h2 > a.a-link-normal');
if (titleElement) {
const title = titleElement.textContent.trim();
// 从 href 中提取 ASIN
const asin = href.match(/dp%2F([^%]+)/);
if (asin && asin.length > 1) {
const asinValue = asin[1];
// 创建新行并插入到表格中
const tr = document.createElement('tr');
const td1 = document.createElement('td');
const td2 = document.createElement('td');
const td3 = document.createElement('td');
td1.textContent = title;
td2.textContent = adId[1];
td3.textContent = asinValue;
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
table.appendChild(tr);
}
}
}
}
});
// 插入表格到页面中
const sgColInner = document.querySelector('.sg-col-inner .s-main-slot');
if (sgColInner) {
sgColInner.insertBefore(table, sgColInner.firstChild);
sgColInner.insertBefore(downloadBtn, table.nextSibling);
}
})();
对用ChatGpt开发亚马逊工具的感兴趣的小伙伴可以转发分享本文后后台截图私聊"用ChatGpt快速开发亚马逊工具"继续加入快闪群,一起共享免费实用的插件工具,大家还有什么好的idea也欢迎来讨论呀!
---优质广告合作服务商伙伴--
---持续招募优质广告合作服务商伙伴--
喜欢此内容的人还喜欢:
写给每一位追梦的人
排版丨林子酱
文案丨林子酱
摄像丨林子酱
我明白你会来,所以我等
完