Greasy Fork is available in English.

讨论 » 开发

Scraping Problems

§
发表于:2020-07-25
编辑于:2020-07-25

Scraping Problems

Hello. Unfortunately I have a problem on one page. I can't get the data URL. The screenshot is attached. Many thanks for the help

wOxxOm管理员
§
发表于:2020-07-25

e.querySelector('div[data-url]').dataset.url

§
发表于:2020-07-25

Thank you very much. Unfortunately, it doesn't work. Is it due to the reference above ??

wOxxOm管理员
§
发表于:2020-07-25

You've lost l at the end.

§
发表于:2020-07-25

what exactly do you mean by that?

wOxxOm管理员
§
发表于:2020-07-25

ur on your screenshot at the end of the copied line should be url.

§
发表于:2020-07-26

wOxxOm is referring to line 36 in your latest screenshot.

§
发表于:2020-07-27

great. unfortunately it doesn't work yet. There is a small error in the code that I cannot find :(

§
发表于:2020-07-27

// ==UserScript== // @name aponeo // @namespace http://tampermonkey.net/ // @version 0.1 // @description aponeo // @author Nexuz89 // @match https://www.aponeo.de/* // @grant none // ==/UserScript==

(function() { 'use strict';

window.setTimeout(installButton, 1000)

function installButton() {
    const elem = document.createElement('button')
    elem.innerText = 'Copy'
    elem.style = 'z-index: 100000; position:fixed; top:0; left:0';
    document.body.appendChild(elem);
    elem.addEventListener('click', _ => exportCsv())
}

function exportCsv() {
    let products = Array.prototype.map.call(document.querySelectorAll("div['apn-product-list-item'"), e => e)
    let csv = products.map(productObject).map(p => '"' + p.title + '",' + p.price + ',"' + p.url + '"').join('\n')
    console.log(csv)
    navigator.clipboard.writeText(csv)
        .then(_ => window.alert('In Zwischenablage kopiert'),
              _ => window.alert('Fehler beim Kopieren in Zwischenablage'))
}

function productObject(e) {
    const result = {};

    result.url = e.querySelector('div[data-url]').dataset.url
    return result
}

})();

发表回复

登录以发表回复。