Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

javascript - How to filter when Webscraping with JSDOM

I would like to geht the following information off a website. I highlighted the Part I wanna extract

You can see the HTML code on the website as well. My code looks like this so far

async function scrape(callback) {

    try {
                  
        const response = await fetch('https://www.sw-ka.de/de/essen/?kw=3');
        const text = await response.text();
        const dom = await new JSDOM(text);
        console.log(dom.window.document.getElementById("fragment-c1-1").textContent);
        
      
    } catch (err) {

        console.error(err);
        console.log("Error detected!");

    }
}

which is returning the entire text of the div:

Linie 1To-GoErbseneintopf mit K?seknacker und Baguettebr?tchen[2,3,ML,Se,We]2,60 €4,00 €3,50 €2,95 €Erbseneintopf mit veganer Wurst und Baguettebr?tchen[Se,So,We]2,60 €4,00 €3,50 €2,95 €zu jedem Gericht ein Dessert und Obst[1,ML]Linie 2To-GoGeschlossenLinie 3GeschlossenLinie 4/5 G&G-Gerichte To-GoGeschlossenSchnitzelbarGeschlossenL6 UpdateGeschlossenSp?tausgabe und AbendessenGeschlossen[k?ri]werk11-14 UhrTo-GoReine Kalbsbratwurst mit Curryso?e und Baguette[Se,Sn,We]2,00 €2,30 €2,30 €2,30 €Vegane Bratwurst mit Curryso?e und Baguette[Se,Sn,So,We]2,00 €2,30 €2,30 €2,30 €Crinkle frites1,20 €1,20 €1,20 €1,20 €CafeteriaBelegte Br?tchen, Kuchen, Snacks etc. und Getr?nke TO GO von 8:00 Uhr bis 14:00 Uhr in der CafeteriaCafeteria11-14 UhrSpeisenausgabe in der Mensa von 11:00 Uhr bis 14:00 Uhr entweder TO GO oder TO PACK[pizza]werkPizza11-14 UhrTo-GoGeschlossen[pizza]werkPastaGeschlossen[pizza]werkSalate / VorspeisenGeschlossen

But i only wanna extract the highlighted part. How do I filter or navigate to that element if it doesnt have an ID?

question from:https://stackoverflow.com/questions/65832952/how-to-filter-when-webscraping-with-jsdom

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...