§
Создано: 25.07.2020
Отредактировано: 25.07.2020

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

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

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

You've lost l at the end.

what exactly do you mean by that?

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

wOxxOm is referring to line 36 in your latest screenshot.

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

// ==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
}

})();

Ответить

Войдите, чтобы ответить.