Eray Bartan
Eray Bartan Blog

Eray Bartan Blog

Web Scraping with Jsdom and NodeJS

Web Scraping with Jsdom and NodeJS

Eray Bartan's photo
Eray Bartan
·Aug 23, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

My goal is to find a data scraping tool compatible with the Nextjs pages/API folder.

The article helped me a lot.

I was able to capture live data with the following file.

const fs = require('fs');
import got from 'got';
import jsdom from "jsdom";
const { JSDOM } = jsdom;
const vgmUrl= '';
export default (req, res) => {
    const eczanelistesi = []
    got(vgmUrl).then(response => {
        const dom = new JSDOM(response.body);
        dom.window.document.querySelectorAll('').forEach(link => {
            const eczaneadi = link.querySelector('h4').textContent
            eczanelistesi.push({'eczaneadi':eczaneadi.toString().replace(/[\n\r]+|[\s]{2,}/g, ' ').trim()});
            name: dom.window.document.querySelector('title').textContent,            
      }).catch(err => {

pages/index.js like;

import Head from "next/head";
import Layout from "../components/layout";
export default function Home({data}) {
  return (
        <title>Property for sale in Bodrum</title>
        <link rel="icon" href="/favicon.ico" />
      <div className="p-4 py-12">
          alt="properties bodrum turkey sale"
          className=" h-64 w-full mt-2 object-cover object-top rounded-xl shadow-xl"
          alt="properties bodrum turkey sale"
      <div className="text-3xl text-center text-red-900">
        Welcom Bodrum Properties
      <div><ul>{ => (



export async function getStaticProps(context) {
   const res = await fetch(``)
  const data = await res.json()
  if (!data) {
    return {
      notFound: true,

 return {
    props: { data }, // will be passed to the page component as props
Share this


Technical Specialties

  • React Native App Development
  • Neo4j Graph Database Beginner Developer
  • Google Data Studio Dashboard Design
  • Micosoft Power BI Dashboard Design

Industry Experience

  • Municiapilty (IT Department, Data Analyst)
  • Real Estate (Web Design, Social Media Publisher, Mailchimp Automation)
  • Hotels & Restaurants (Web Design, Google Ads , Facebook Ads)
  • Sports (Web Design, Mailchimp Campaign)