拼多多采集

pdd采集

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         拼多多采集
// @namespace    http://tampermonkey.net/
// @version      2024-12-23
// @description  pdd采集
// @author       bzy
// @match        https://mobile.yangkeduo.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=microsoft.com
// @run-at       document-end
// @grant        GM_xmlhttpRequest
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function sendRequest2(method, url, data = null, callback = null, headers = {}) {
        // 创建 XMLHttpRequest 对象
        const xhr = new XMLHttpRequest();

        // 配置请求
        xhr.open(method, url, true);

        // 设置请求头(可以根据需要自定义)
        for (const key in headers) {
            xhr.setRequestHeader(key, headers[key]);
        }

        // 设置请求完成后的回调函数
        console.log(url)
        xhr.onload = function() {
            if (xhr.status >= 200 && xhr.status < 300) {
                console.log("已上传")
                // 请求成功
                if (callback) callback(null, xhr.responseText);
            } else {
                console.log("失败")
                // 请求失败
                if (callback) callback(new Error(`Request failed with status ${xhr.status}`));
            }
        };

        // 处理请求错误
        xhr.onerror = function() {
            if (callback) callback(new Error('Network error'));
        };

        // 发送请求(如果有请求体,则发送数据)
        xhr.send(data);
    }

    let url = window.location.href
    // unsafeWindow.alert("找到商品")
    if (url.includes('mobile.yangkeduo.com/goods2.html?goods_id')) {
        try {
            const urlParams = new URLSearchParams(window.location.search);
            const goodsId = urlParams.get("goods_id");
            const userId = urlParams.get("user_id");
            let pageHTML = document.documentElement.outerHTML
            const regex = /window\.rawData\s*=\s*(.*?);/s;
            const match = pageHTML.match(regex);
            // const rawDataValue = match[1].trim();
            // console.log("window.rawData 的值为:", rawDataValue);
            // alert(match[1])
            if (match && match[1]) {
                // unsafeWindow.fetch ("http://45.136.13.81:5002/up", {"body": "{'123': '456'}"})
                // alert("有商品")
                const rawDataValue = match[1].trim();
                if (rawDataValue.includes("商品已售罄")) {
                    return
                }
                url = "http://45.136.13.81:5002/up"
                GM_xmlhttpRequest({
                    "url": url,
                    "data": JSON.stringify({
                        "goods_id": goodsId,
                        "goods_detail":rawDataValue,
                        "use":"005"
                    }),
                    "method": "POST",
                    "headers": {"Content-Type":"application/json"},
                    "onload": (res) => {
                        console.log(JSON.stringify(res))
                    }
                })


                sendRequest2("GET", "https://pddcj.https7.com/api/v1/other/achieve?goods_id=" + goodsId + "&status=1&user_id=" + userId )
            } else {
                console.log("没有找到");
            }
        } catch (error) {
            alert("出错" + error)
        }

    }
})();