Everything You NEED to Know about Web Scraping (Advanced)

ForrestKnight
8 Mar 202415:02

Summary

TLDRIn diesem Video teilt Forest seine Erfahrungen mit Web-Scraping, einem Prozess, der das Extrahieren von Daten aus Websites beinhaltet. Er erklärt, wie man mit komplexen Web-Technologien wie SPA und Ajax umgeht, wie man Anpassungen und Algorithmen optimiert, wie man mit IP-Bannen und Anti-Scraping-Schutz umgeht und schließlich, wie man die extrahierten Daten verwaltet und integriert. Forest betont dabei die Bedeutung der ethischen und rechtlichen Einhaltung bei solchen Aktivitäten und empfiehlt Werkzeuge wie Bright Data, um sicherzustellen, dass man auf der rechten Seite bleibt.

Takeaways

  • 🌐 Web Scraping ist der Prozess des Extrahierens von Daten aus einer Webseite mittels programmatischer Anfragen.
  • 🔍 Es ist wichtig, Web Scraping ethisch und legal durchzuführen, um Verstöße gegen Datenschutzgesetze oder Nutzungsbedingungen zu vermeiden.
  • 🛠️ Wichtige Tools für Web Scraping sind Selenium, Playwright, Puppeteer und Beautiful Soup, die für Browserautomatisierung und HTML/XML-Dokumentenparsing verwendet werden.
  • 📊 Web Scraping findet in der echten Welt Anwendung in Bereichen wie Preisvergleich, Aktienkurseüberwachung, Nachrichtenartikelextraktion und Immobilienanzeigenaggregation.
  • 🔄 Bei der Verarbeitung von Web-Technologien wie SPA und Ajax ist es notwendig, asynchron geladene Inhalte korrekt zu rendern und zu extrahieren.
  • 💡 Script-Optimierung, Fehlerbehandlung und adaptive Algorithmen sind entscheidend für die Effizienz und Zuverlässigkeit von Web-Scraping-Projekten.
  • 🔒 IP-Banns können durch den Einsatz von Proxies verhindert werden, insbesondere intelligente Proxy-Management-Systeme, die IP-Adressen rotieren und anonymisieren.
  • 🚀 Für die Verarbeitung großer Datenmengen ist es wichtig, geeignete Datenbanken und ETL-Tools (Extrahieren, Transformieren, Laden) zu verwenden.
  • 📊 Datenanalyse und Business Intelligence-Tools wie Tableau oder Power BI können nach dem Web Scraping eingesetzt werden, um Erkenntnisse aus den gesammelten Daten zu gewinnen.
  • 🔒 Die Nutzung von Web-Scraping-Dienstleistungen wie Bright Data hilft dabei, die Compliance mit Gesetzen und Nutzungsbedingungen sicherzustellen.

Q & A

  • Was ist Web Scraping und wie funktioniert es?

    -Web Scraping ist der Prozess des Extrahierens von Daten aus einer Webseite. Dies geschieht durch das programmgesteuerte Senden von Anfragen an eine Webseite, das Empfangen der Daten und das Parsen der Daten um spezifische Datenpunkte zu extrahieren, die dann für verschiedene Zwecke verwendet werden können.

  • Warum ist Web Scraping wichtig und wo wird es angewendet?

    -Web Scraping ist wichtig, da es Unternehmen dabei hilft, öffentlich verfügbare Daten für Analysen, Entscheidungen und Automatisierung zu nutzen, was potenziell Millionschlösse sparen oder generieren kann. Anwendungsbeispiele sind die Zusammenstellung von Produktinformationen für den Vergleichskauf, das Überwachen von Aktienkursein, das Extrahieren von Nachrichtenartikeln für Analysen oder die Aggregation von Immobilienanzeigen.

  • Welche Tools sind für Web Scraping besonders nützlich und wie funktionieren sie?

    -Nützliche Tools für Web Scraping sind Selenium, Playwright und Puppeteer, die es ermöglichen, Skripte in verschiedenen Programmiersprachen für Browserautomatisierung zu erstellen. Es gibt auch Tools wie Beautiful Soup für das Parsen von HTML und XML Dokumenten. Diese Tools helfen bei der Verwaltung komplexer Browserinteraktionen, der Vermeidung von IP-Banns durch Proxy-Rotation und der sicheren Erfassung von dynamisch geladenem Inhalt über Ajax oder JavaScript.

  • Wie kann man Web Scraping legal und ethisch durchführen?

    -Um Web Scraping legal und ethisch durchzuführen, ist es wichtig, die Datenschutzgesetze und Nutzungsbedingungen der jeweiligen Webseiten zu beachten. Es ist ratsam, Tools zu verwenden, die sicherstellen, dass die Scraping-Aktivitäten rechtens sind, und sich bewusst zu sein, dass einige Nutzungsbedingungen möglicherweise nicht rechtlich bindend sind, wenn sie öffentliche Daten ohne technische Barrieren wie Login oder ähnliches abrufen.

  • Was sind einige der Herausforderungen bei der Web Scraping von Single-Page-Applications (SPAs) und wie kann man sie lösen?

    -SPAs und Ajax machen Websites interaktiver und dynamischer, stellen jedoch bei Web Scraping Herausforderungen dar, da der initial geladene HTML nicht alle benötigten Daten enthält. Um dies zu lösen, kann man Skripte mit Wartezeiten oder Intervallen schreiben, um Ajax-geladene Inhalte zu laden, sowie Interaktionen mit der Webseite simulieren, um die benötigten Daten direkt im DOM zu extrahieren.

  • Wie kann man Skripte optimieren, um die Effizienz beim Web Scraping zu erhöhen?

    -Script-Optimierung kann durch die Verwendung effizienter XPath oder CSS-Selektoren, die Reduzierung unnötiger Parse-Operationen, die Implementierung von Wiederholungen für Server-Timeouts, die Protokollierung unerwarteter HTML-Strukturen für Analyse und die Verwendung adaptiver Algorithmen zur Erkennung von Layoutänderungen auf Seitenebene durchgeführt werden, um das Scrapingmuster automatisch anzupassen.

  • Was sind IP-Banns und wie kann man sie vermeiden?

    -IP-Banns tritt auf, wenn ein Service aufgrund der Annahme, dass Anfragen von einem Web-Scrapers stammen, eine IP-Adresse sperrt. Dies kann durch die Verwendung von Proxy-Management-Systemen verhindert werden, die eine Poolverwaltung von Proxies ermöglichen, um Anfragen zu verteilen und die IP-Adresse zu maskieren, sowie durch die Implementierung von intelligenten Rate-Limiting-Algorithmen, um das Scrapingverhalten natürlicher erscheinen zu lassen und Anti-Scraping-Schutzmaßnahmen zu umgehen.

  • Wie kann man extrahierte Daten speichern und integrieren?

    -Nach dem Scraping müssen die Daten gespeichert und für Analysen und Nutzung integriert werden. Dies kann durch die Auswahl einer Datenbanklösung, wie NoSQL-Datenbanken wie MongoDB oder Cassandra für unstrukturierte Daten oder SQL-Datenbanken wie PostgreSQL oder MySQL für strukturierte Daten geschehen. Zusätzlich kann man ETL-Tools verwenden, um die Daten zu bereinigen, zu transformieren und in bestehende Systeme zu integrieren, und Big Data-Plattformen wie Apache Hadoop oder Spark für verteiltes Speichern und Verarbeiten zu nutzen.

  • Welche Vorteile bringen automatisierte Prozesse im Vergleich zu manuellen Arbeitsschritten?

    -Automatisierte Prozesse sparen Zeit und Ressourcen, indem sie die Effizienz und Zuverlässigkeit von Datenextraktion und -verarbeitung erhöhen. Sie ermöglichen es, Aufgaben zu automatisieren, die sonst viel Zeit in Anspruch nehmen würden, und geben den Benutzern Freizeit, um andere Aktivitäten zu verfolgen oder sich auf wichtigere Aufgaben zu konzentrieren.

  • Wie kann man sicherstellen, dass Web Scraping-Aktivitäten rechtlich und ethisch korrekt sind?

    -Um sicherzustellen, dass Web Scraping-Aktivitäten rechtlich und ethisch korrekt sind, ist es wichtig, die Datenschutzgesetze und Nutzungsbedingungen der jeweiligen Webseiten zu beachten. Es ist ratsam, Tools zu verwenden, die sicherstellen, dass die Scraping-Aktivitäten rechtens sind, und sich bewusst zu sein, dass einige Nutzungsbedingungen möglicherweise nicht rechtlich bindend sind, wenn sie öffentliche Daten ohne technische Barrieren wie Login oder ähnliches abrufen.

  • Welche Rolle spielt die Verwendung von Proxys bei der Vermeidung von IP-Banns?

    -Die Verwendung von Proxys ermöglicht es, Anfragen von verschiedenen IP-Adressen aus zu stammen, was die Identifizierung und Sperrung einer einzelnen IP-Adresse durch den Server erschwert. Dies ist besonders nützlich, wenn man große Mengen von Daten von einer Webseite extrahieren möchte, um Anfragen zu verteilen und die Wahrscheinlichkeit eines IP-Banns zu verringern.

  • Wie kann man dynamisch geladene Inhalte bei Web Scraping sicher extrahieren?

    -Dynamisch geladene Inhalte können durch die Verwendung von Skripten, die Wartezeiten oder Intervalle implementieren, um die Ladezeiten von Ajax-geladenen Inhalten abzuwarten, sicher extrahiert werden. Zusätzlich kann das Scrollen und Klicken auf der Webseite simuliert werden, um weitere Inhalte zu laden, die nicht sofort im HTML enthalten sind.

  • Welche Tools gibt es, um Web Scraping-Aktivitäten rechtlich und ethisch sicher zu gestalten?

    -Es gibt Tools wie das Bright Data Trust Center, das darauf abzielt, sicherzustellen, dass Web Scraping-Aktivitäten sowohl rechtlich als auch ethisch korrekt durchgeführt werden. Diese Tools helfen dabei, die Einhaltung von Datenschutzgesetzen und Nutzungsbedingungen zu gewährleisten und bieten Unterstützung bei der Überprüfung der Compliance von Scraping-Projekten.

Outlines

00:00

🌐 Einführung in das Web Scraping

Forest, der Sprecher des Videoscripts, hat viel Erfahrung im Web Scraping gesammelt und ist mit Herausforderungen wie 403 Forbidden-Fehlern, 500 internen Serverfehlern, nicht beachteten captures oder dem Blockieren seiner IP durch Websites konfrontiert gewesen. Er hat gelernt, wie man diese Probleme bekämpft, indem man sich mit komplexen Web-Technologien wie SPA und Ajax auseinandersetzt, Skript-Optimierung durchführt, Anpassungsalgorithmen mit Proxy-Management nutzt, intelligente Rate-Limiting anwendet und extrahierte Daten mit Datenspeicherung und Big Data-Integration verarbeitet. Forest erklärt, dass Web Scraping das Extrahieren von Daten aus Websites ist und wie es in der realen Welt eingesetzt wird, um beispielsweise Tech-Nachrichten für eine Newsletter zu kuratieren.

05:02

🛠️ Handhabung komplexer Web-Technologien

Forest erklärt die Herausforderungen, die mit der Verwendung von Single Page Applications (SPAs) und asynchronem JavaScript (Ajax) im Zusammenhang mit Web Scraping verbunden sind. Er beschreibt, wie man mit Selenium, Playwright oder Puppeteer Skripte schreibt, um dynamisch geladene Inhalte auf Websites zu laden und zu extrahieren. Er diskutiert auch die Verwendung des Scraping-Browsers, um Ajax-geladene Inhalte sicher zu rendern und zu erfassen, und Web Unlocker, um Anti-Scraping-Schutzmaßnahmen zu umgehen. Forest betont die Wichtigkeit von Script-Optimierung, Fehlerbehandlung und adaptiven Algorithmen, um große Datenmengen effizient und zuverlässig zu extrahieren.

10:05

🔒 IP-Management und Datenverarbeitung

Forest erläutert, wie man IP-Banns vermeiden kann, die bei großen Datenmengen auftreten können, indem man Proxys verwendet. Er spricht über die Verwendung von AI-gestützter Proxy-Management-Systemen, um Anfragen zu verteilen und die Anonymität zu wahren. Er erklärt auch, wie man mit intelligenten Rate-Limiting die Anfragen anpasst, um Anti-Scraping-Schutzmaßnahmen zu umgehen. Forest diskutiert dann, wie man die extrahierten Daten speichern und integrieren kann, um sie für Analysen und Nutzung zu verwenden, und betont die Notwendigkeit, dies ethisch und legal zu tun.

Mindmap

Keywords

💡Web Scraping

Web Scraping bezeichnet den Prozess des Extrahierens von Daten von Websites durch das Programmieren von Anfragen, die Daten empfangen, spezifizieren und analysieren. Im Video wird beschrieben, wie Web Scraping genutzt wird, um Daten automatisch von verschiedenen Technologienachrichten-Websites zu sammeln und in einem konsolidierten Bereich für die Überprüfung und Aufnahme in einen Newsletter zusammenzuführen. Dies illustriert, wie Web Scraping in der Praxis eingesetzt wird, um Zeit zu sparen und Effizienz zu steigern.

💡Anti-Scraping-Schutz

Anti-Scraping-Schutz bezieht sich auf Methoden und Technologien, die von Websites verwendet werden, um zu verhindern, dass ihre Daten durch Web Scraping-Tools extrahiert werden. Der Sprecher im Video erwähnt Tools wie Web Unlocker, die dazu dienen, diese Schutzmaßnahmen zu umgehen, einschließlich CAPTCHAs und Browser-Fingerabdrücke. Dies betont die Notwendigkeit, innovativ zu sein und fortgeschrittene Lösungen einzusetzen, um effektiv Daten zu sammeln.

💡Proxy-Management

Proxy-Management ist eine Technik, die im Video hervorgehoben wird, um IP-Adressen zu verbergen und IP-Bans zu vermeiden. Durch die Verteilung von Anfragen über mehrere Proxies kann ein Scraper die Erkennung durch Zielwebsites erschweren. Diese Methode ist besonders nützlich beim Sammeln von Daten von großen Websites, die ihre Inhalte aktiv vor dem Scraping schützen.

💡Rate Limiting

Intelligentes Rate Limiting bezieht sich auf die Praxis, die Häufigkeit von Anfragen an eine Website zu kontrollieren, um Anti-Scraping-Schutzmechanismen nicht auszulösen. Im Video wird beschrieben, wie Algorithmen entwickelt werden können, um die Anfragerate dynamisch anzupassen, sodass sie menschlicher Aktivität ähnelt. Dies minimiert das Risiko, erkannt und blockiert zu werden.

💡Datenintegration

Datenintegration ist der Prozess des Kombinierens von Daten aus verschiedenen Quellen in einem einheitlichen, zugänglichen Format. Im Kontext des Videos wird erklärt, wie extrahierte Daten für Analysen und Nutzung vorbereitet werden, einschließlich der Speicherung in Datenbanken und der Verwendung von ETL-Tools (Extract, Transform, Load) zur Reinigung und Integration der Daten in bestehende Systeme.

💡SPA (Single Page Application)

Single Page Applications (SPAs) sind Webanwendungen, die eine einzige HTML-Seite verwenden, die dynamisch aktualisiert wird, während der Benutzer interagiert, um eine kontinuierliche und nahtlose Benutzererfahrung zu bieten. Im Video wird ihre Rolle bei der Erschwerung des Web Scrapings diskutiert, da SPAs Inhalte asynchron laden und somit traditionelle Scraping-Methoden herausfordern.

💡AJAX (Asynchronous JavaScript and XML)

AJAX steht für Asynchronous JavaScript and XML und bezeichnet eine Technik zur Erstellung interaktiver Webanwendungen, die es ermöglicht, Daten mit dem Server auszutauschen und die Seite zu aktualisieren, ohne die Seite neu laden zu müssen. Das Video thematisiert, wie AJAX das Web Scraping kompliziert, da Daten dynamisch geladen werden und spezielle Techniken erforderlich sind, um sie zu erfassen.

💡Browser-Automatisierung

Browser-Automatisierung bezieht sich auf die Verwendung von Softwaretools wie Selenium, Playwright und Puppeteer zur Steuerung eines Webbrowsers. Diese Tools simulieren Benutzerinteraktionen auf Webseiten, um Daten zu extrahieren, insbesondere von Seiten, die dynamischen Inhalt wie SPA oder AJAX nutzen. Im Video wird ihre Bedeutung für das Überwinden von Herausforderungen bei der Datenerfassung betont.

💡Datenspeicher

Datenspeicherung bezieht sich auf die Methoden und Technologien, die zur Speicherung von extrahierten Daten verwendet werden. Das Video erklärt, wie wichtige Entscheidungen bezüglich der Verwendung von SQL oder NoSQL-Datenbanken, der Datenpartitionierung und der Indexierung getroffen werden müssen, um die Leistung von Abfragen zu verbessern und eine effiziente Analyse großer Datenmengen zu ermöglichen.

💡Ethisches und legales Scraping

Ethisches und legales Scraping bezieht sich auf die Praxis, Daten in einer Weise zu sammeln, die sowohl moralisch vertretbar als auch im Einklang mit geltendem Recht steht. Der Sprecher im Video betont die Bedeutung, die Gesetze und die Nutzungsbedingungen von Websites zu respektieren, um rechtliche Konsequenzen zu vermeiden. Dies unterstreicht die Notwendigkeit einer sorgfältigen Abwägung der rechtlichen Aspekte des Web Scrapings.

Highlights

Experience with web scraping and handling common issues like 403 Forbidden errors and IP blocking.

Adaptation of techniques over the years to combat web scraping issues, including handling SPA, Ajax, and using proxy management.

Utilization of AI-driven anonymity, intelligent rate limiting, and big data integration for advanced web scraping.

Ethical and legal considerations when performing web scraping to ensure compliance with laws and platform terms of service.

Definition of web scraping as a process of programmatically extracting data from websites.

Real-world applications of web scraping such as curating newsletters, gathering product info, monitoring stock prices, and more.

Popular web scraping tools like Selenium, Playwright, Puppeteer, and BeautifulSoup.

Use of Scraping Browser and Web Unlocker for managing complex browser interactions and bypassing anti-scraping protections.

Contact with Bright Data for sponsorship and use of their suite of tools for web scraping.

Challenges posed by single-page applications and asynchronous JavaScript in web scraping.

Script optimization, error handling, and adaptive algorithms for efficient large-scale data extraction.

IP bans and the use of proxy management to distribute requests and mask IP addresses.

Intelligent rate limiting to adjust request frequency and avoid triggering anti-scraping protections.

Data storage solutions and ETL tools for cleaning, transforming, and integrating scraped data into existing systems.

Use of big data platforms like Apache Hadoop or Spark for distributed storage and processing.

Delivery methods for scraped data including email, webhook, cloud storage solutions, and SFTP.

Implementation of data analytics and business intelligence tools for extracting insights from data sets.

Transcripts

play00:00

hey my name is Forest welcome back so

play00:01

I've done quite a bit of web scraping

play00:03

over the years and I've definitely

play00:04

gotten my fair share of 403 Forbidden

play00:06

errors 500 internal server errors

play00:09

captures I didn't account for or my IP

play00:11

just straight up getting blocked if you

play00:13

know you know unfortunately but that's

play00:16

the game and over the years I've learned

play00:18

how to combat these issues like handling

play00:21

complex web Technologies like spa and

play00:24

Ajax optimizing my scripts aor handling

play00:27

and adaptive algorithms utilizing proxy

play00:29

management now ai driven anonymity and

play00:32

intelligent rate limiting and handling

play00:34

extracted data with data storage and Big

play00:36

Data integration and I know a lot of

play00:38

buzzwords it seems but it we'll dis

play00:41

demystify all of that it's really not as

play00:43

complicated as it sounds once you're on

play00:45

the other side of it oh yeah and doing

play00:48

all of that ethically and legally I mean

play00:50

if we have to and what I've done is I've

play00:52

taken all of that experience plus some

play00:54

research beforehand just to make sure

play00:56

that the way I do things is the actual

play00:57

correct way to do things and packaged it

play00:59

nicely into this little video so I hope

play01:02

you enjoy it and to get everyone up to

play01:03

speed I'm going to quickly trust me very

play01:06

quickly answer these questions what is

play01:08

web scraping how does it work why is it

play01:11

important and how is it used in the real

play01:13

world if you already know all of that

play01:14

feel free to skip around using the

play01:16

timestamps web scrap being simply put is

play01:18

a process of extracting data from a

play01:20

website you programmatically send

play01:22

requests to a website receive the data

play01:24

you specified in your code it all goes

play01:26

well parse the data to extract specific

play01:28

data points and then use said data for

play01:30

whatever need you have so for me instead

play01:32

of going to every single Tech News

play01:35

website trying to manually pull all of

play01:37

these articles of software engineering

play01:39

and computer science in order to curate

play01:41

devotes newsletter what I've done is

play01:42

I've written a script that

play01:44

programmatically checks all of these

play01:46

websites based on the categories and

play01:48

what I've written and pulls in all of

play01:51

these articles into a Consolidated area

play01:53

so then I can go through them and see

play01:56

what I want to include that's a real

play01:58

word example other real word examples

play02:00

would include Gathering product

play02:01

information for comparison shopping

play02:03

monitoring stock prices extracting news

play02:06

articles for cinnamon analysis

play02:08

aggregating real estate listings and a

play02:10

whole lot more it's a very useful skill

play02:13

to have because businesses need this

play02:15

information they need to leverage

play02:17

publicly available data for analysis

play02:20

decisionmaking automation a lot of

play02:23

things that could potentially save them

play02:25

or make them millions of dollars which

play02:27

makes you the webscraper a very valuable

play02:30

resource to them that's web scraping and

play02:32

some of the most popular tools are

play02:34

selenium playright and Puppeteer which

play02:37

allow you to create scripts and various

play02:38

programming languages for browser

play02:40

automation there's also tools like

play02:41

beautiful sup for parsing HTML and XML

play02:44

documents and there are a whole lot more

play02:45

there's there are a lot of weed that you

play02:47

can get into what I do is I actually use

play02:50

this tool kind of in conjunction with

play02:52

the former three that I just listed

play02:55

called scraping browser that I just put

play02:57

my Puppeteer script into or playwright

play02:59

or selenium scripts and it helps with

play03:01

managing any complex browser

play03:02

interactions it'll also automate proxy

play03:04

rotations for avoiding IP bands and make

play03:07

sure that Dynamic content loaded via

play03:09

Ajax or JavaScript is actually rendered

play03:11

and captured because I've had trouble

play03:13

with that sometimes and I also use this

play03:14

tool called Web unlocker that helps with

play03:17

bypassing anti-scraping protections that

play03:19

would be your capes browser fingerprint

play03:21

and and all that stuff and in

play03:23

preparation for this video I actually

play03:25

contacted the company behind those tool

play03:27

to two two tools as well as a an entire

play03:31

Suite of tools called bright data I

play03:34

wanted them to sponsor this video and

play03:35

they happily obliged I'm sure you've

play03:37

already heard of them I will be talking

play03:39

about them a little bit more later in

play03:40

the video but I mention them now because

play03:42

I want to clarify this video is about

play03:44

web scraping and the issues that I faced

play03:47

and the solutions I've implemented to

play03:49

well solve those issues I've made this

play03:52

video as if there was no sponsor just

play03:55

talking about my knowledge and what I

play03:57

just said it just so happens that uh

play03:59

however many years a ago I went on this

play04:00

trip with a bunch of data scientists and

play04:02

data engineers and the like which was

play04:05

sponsored by bright data and ever since

play04:07

then I've been using their Suite of

play04:08

tools they have tools they have proxies

play04:10

they have existing data sets so you can

play04:12

just use their data sets instead of

play04:13

scrape everything yourself and a whole

play04:15

ly of other things that are just pretty

play04:17

dang good at scraping the web and that's

play04:19

why I use them but again in this video

play04:22

you will learn everything you need to

play04:23

know about these Solutions about these

play04:26

problems and these Solutions regardless

play04:28

of what tools you use so that's the

play04:30

overview of web scraping how it's done

play04:33

and what tools you use to do it so now

play04:35

let's get on to the more advanced stuff

play04:38

first handling complex web Technologies

play04:41

look I love making websites that are

play04:44

single page applications or spas and I

play04:47

love utilizing asynchronous JavaScript

play04:49

in XML or in other words Ajax I'm pretty

play04:52

sure that's the only time I've ever said

play04:54

that acronym out the entire thing they

play04:56

make websites more interactive and

play04:58

dynamic but when it comes to web

play04:59

scraping I hate them if you don't know

play05:02

what it is just scroll all the way to

play05:04

the bottom of this web page right now

play05:07

actually like on YouTube Just scroll

play05:08

down you'll notice that it stops if you

play05:10

go you got to go real quick and notice

play05:12

that it stops then it'll load some more

play05:14

comments or some more recommended videos

play05:16

over there that's Dynamic content

play05:18

loading and I hate it when web scraping

play05:21

because it poses a challenge that I just

play05:22

wish I didn't have and that is instead

play05:24

of just being able to go to the website

play05:26

and say okay give me all that data the

play05:28

initial HTML on web pages like this it's

play05:30

not all there however it's loaded

play05:34

asynchronously to the D so what we can

play05:37

do is write a script using selenium

play05:39

playwright or Puppeteer to navigate to

play05:42

the Target website that again loads HTML

play05:45

without all the data we need so then in

play05:46

our script we will Implement weights or

play05:48

intervals to allow Ajax loaded content

play05:51

to appear as well as trigger ack's calls

play05:54

by interacting with the web page by

play05:55

doing things like clicking and scrolling

play05:58

this is what loads the data that we

play05:59

actually need directly in the domm for

play06:02

us to then be able to extract however

play06:04

even with that I've had some of this

play06:07

content failed to properly load so what

play06:09

I'll do is Port my script into scraping

play06:12

browser to make sure the Ajax loaded

play06:14

content actually renders or if instead I

play06:17

get hit by some anti-scraping

play06:19

protections I'll route my request

play06:21

through the web un Locker to account for

play06:22

all that now script optimization error

play06:25

handling adaptive algorithms we've

play06:28

actually discussed this over idea in one

play06:30

way or another in three of my last four

play06:33

videos that is sometimes you can get

play06:35

away with writing trash code using

play06:38

incorrect data structures and

play06:40

inefficient algorithms when your project

play06:43

is on a smaller scale but if you try to

play06:46

do the same on a large scale project

play06:49

those really take their toll and just

play06:51

like that in you know a typical

play06:53

programming project this would be the

play06:55

same when you're dealing with large

play06:57

scale data extraction you have to make

play06:59

sure sure everything is efficient and

play07:01

reliable let me give you an example say

play07:03

you're scraping for price comparisons on

play07:06

Amazon or Walmart these are large

play07:08

websites that want to protect their data

play07:10

so you'll likely face issues with server

play07:13

timeouts or changes in website structure

play07:15

within the same website because it's so

play07:17

large and rate limits you have to figure

play07:20

out how to address these things if you

play07:22

want any chance in actually scraping

play07:24

this data and there are many many ways

play07:26

to do it to optimize your script you can

play07:29

use efficient xath or css selectors

play07:32

which reduces unnecessary parsing

play07:34

cutting it off your workload to handle

play07:36

errors you can Implement retries for

play07:38

Server timeouts taking the manual aspect

play07:40

out of it and logging unexpected HTML

play07:43

structures for analysis and finally you

play07:46

can utilize an Adaptive algorithm to

play07:48

detect when product pages layouts change

play07:51

then automatically adjust the scraping

play07:53

pattern accordingly implementing just

play07:55

these few things will greatly improve

play07:57

the efficiency and effective

play07:59

of your scraping process which will

play08:01

impress your boss because you got it

play08:03

done so quick or maybe you decide to

play08:05

hold on to it you free out some time at

play08:08

work and now you can read a book or play

play08:10

some video games I don't care what you

play08:12

do in all seriousness it will free up

play08:16

your time your future time because it's

play08:18

now future proofed in perpetuity what

play08:21

you do with that information is

play08:22

completely up to you what will also

play08:24

happen more often when you're scraping

play08:25

data on a large scale IP banss so

play08:28

another example you guys know how much I

play08:30

love examples it's just how I'm able to

play08:32

like really understand something like

play08:34

using an analogy and example so I assume

play08:37

that it helps y'all too I don't know

play08:39

hopefully it does but it's like if

play08:41

you're scraping a travel site for flight

play08:43

prices all right they can see all of

play08:45

these requests coming from the same IP

play08:49

address and they can see that these

play08:51

requests are coming in at a rate much

play08:54

faster than a human can actually do it

play08:57

accessing whoa that was a difficult one

play08:58

access accessing a lot of data this

play09:01

makes it very very easy for them to

play09:04

detect you as a web scraper and flag you

play09:07

for doing it and banning your IP the

play09:10

solution proxies but not simply proxies

play09:14

Aid driven proxy management using a pool

play09:16

of proxies to distribute requests which

play09:19

masks your IP address if nothing else

play09:22

this is really when you want to use a

play09:23

service like bright data because there

play09:25

is really no point in trying to whip all

play09:28

of this up yourself I'm pretty sure they

play09:29

have like over 72 million yeah no yeah

play09:33

72 over 72 million IPS rotating from

play09:38

about I think

play09:40

195 different countries yeah don't try

play09:43

to do that yourself and you can see what

play09:45

else they have here namely rotating

play09:47

proxies for web scraping at scale you

play09:49

also want to ensure anonymity so even if

play09:51

they do kind of detect you they can't

play09:53

you know Point directly to you which

play09:55

rotating proxies also do that and

play09:57

intelligent rate limiting so what you do

play09:59

is you you dynamically adjust the rate

play10:02

of requests so it seems a little bit

play10:05

more human it it it really just helps

play10:07

you avoid like triggering those

play10:09

anti-scraping protections that we

play10:11

previously discussed and when I say you

play10:13

do all of this I don't mean you I mean

play10:14

you write the algorithm and then the

play10:16

algorithm does all of this it learns the

play10:19

optimal rate over time and adjusts the

play10:21

frequency of requests according to that

play10:23

but scraping isn't the entirety of the

play10:25

job now you got to figure out what the

play10:26

heck do I do with this data so once you

play10:28

successfully scrape it you have to store

play10:31

it then integrate the data for analysis

play10:33

and usage for example a market research

play10:36

firm may need to scrape uh reviews of

play10:41

something from various different sites

play10:42

like Yelp over here Google reviews over

play10:44

here whatever the heck else is over here

play10:46

so then they'll have it all Consolidated

play10:48

but if they're scraping this data that

play10:50

means there's a lot of it otherwise if

play10:52

there's like three over here four over

play10:53

there six over there when there's 13 you

play10:55

can just manually do that unless you're

play10:56

a true developer that takes three days

play10:58

automating something that otherwise will

play10:59

take 3 hours and you only really need to

play11:01

do it once so what you need to do first

play11:03

is choose a database solution for the

play11:05

large scale data there are no SQL

play11:07

databases like mongodb or Cassandra

play11:09

Cassandra if it's unstructured or SQL

play11:12

databases like postgressql or MySQL my

play11:15

SQL if it's structured and Implement

play11:17

data partitioning and indexing

play11:19

strategies as needed to improve query

play11:21

performance then you use ETL tools to

play11:23

clean transform and integrate the scrape

play11:26

data into existing systems or we should

play11:29

probably say extract transform and load

play11:31

the data that's that's what ETL stands

play11:34

for and ensuring data formats and

play11:36

schemas are consistent for seamless

play11:37

integration and the formats for this

play11:39

will typically be Json Indie Json CSV

play11:43

and xlsx now you can leverage Big Data

play11:46

platforms like Apache Hood dup or spark

play11:49

for distributed storage and processing

play11:51

and then delivering said data you can do

play11:53

this via email for immediate reports web

play11:56

hook for real-time data integration

play11:58

cloud storage Solutions like Amazon S3

play12:00

or Google Cloud Storage for scalable

play12:03

access SFTP for obviously secure file

play12:06

transfers and Microsoft Azure Azure

play12:08

Azure if and really only if you're

play12:11

already invested in the ecosystem to

play12:12

where now you can finally Implement data

play12:14

analytics and business intelligence

play12:16

tools to extract insights from these

play12:19

data sets using Tableau or powerbi or

play12:22

something and in doing everything I laid

play12:24

out here today you must make sure you do

play12:28

it all ethically and legally I know I

play12:31

joked about it before but it's kind of

play12:33

important for example if my company

play12:36

needed me to scrape social media sites

play12:39

for Consumer sentiment analysis we must

play12:42

ensure what I'm doing does not violate

play12:45

violate any privacy laws or the

play12:49

platform's terms of service I just saw

play12:52

some people irk a little bit like oh the

play12:54

terms of service are unlawful that was

play12:56

my next point because some of these

play12:57

terms of service are technically not

play13:00

lawful themselves if I'm pulling public

play13:03

data displayed on their site without

play13:05

breaching any technical barriers you

play13:07

know like login or something like that

play13:09

it may not constitute a legal violation

play13:12

even if it does go against their to cuz

play13:14

there are Protections in place but guess

play13:17

what I know this may come come as a

play13:20

surprise to some of y'all I'm not a

play13:23

lawyer I'm not here to give legal advice

play13:25

nor could I even if I wanted to I'm only

play13:28

here to say that before you start web

play13:30

scraping make sure you ain't breaking

play13:31

any laws I don't want a bunch of YouTube

play13:33

comments under this video coming from

play13:35

the iPhone you snuck in jail that's all

play13:37

I'm going to say and what I actually

play13:39

find beneficial and that's the reason

play13:41

that's all I'm going to say not just

play13:42

because I'm not a lawyer but because I

play13:45

use tools that make sure that I can't be

play13:48

breaking these laws right data their

play13:50

tools their platform they really make

play13:53

sure like they're very proud of it they

play13:55

have a whole bright data bright dat.com

play13:58

SL trust Center to make sure that

play14:01

everything is in compliance is ethical

play14:04

not just legal because there's a

play14:06

difference there sometimes but also

play14:08

ethical when it comes to web scraping

play14:10

and they make sure that I am completely

play14:12

above board so that's one one more thing

play14:15

off my plate and with that I hope you

play14:17

gained some knowledge here if you could

play14:20

click the Subscribe button subscribe to

play14:22

the channel turn on the Bell

play14:23

notifications I'd greatly appreciate it

play14:25

oh and when I said that did the

play14:28

Subscribe but button light up it's been

play14:30

doing that for some users or is it the

play14:32

like button let's try that like the

play14:34

video did that work what about subscribe

play14:38

to the YouTube channel did that work

play14:41

also did you actually hit the like

play14:42

button or subscribe button or you just

play14:43

getting distracted with the animations I

play14:46

just let me know if it worked let me

play14:47

know if you actually liked it and

play14:48

subscribed well you don't have to just

play14:50

make sure you do it anyway I genuinely

play14:52

hope that you have a wonderful day again

play14:55

I'm forest forest forest forest

play14:59

pronounce it how you wish I'll see you

play15:01

in the next video

Rate This

5.0 / 5 (0 votes)

Related Tags
Web-ScrapingDatenextraktionSeleniumPlaywrightPuppeteerProxy-ManagementAI-AnonymitätRate-LimitingBig-DataDatenintegrationTech-NewsSoftware-EntwicklungEthische-Rechtliche
Do you need a summary in English?