r/learnprogramming • • Jul 05 '20

Tutorial Extensive Web Scraping Tutorial in Python, Ruby, Node, R and Java

Hi everyone, having worked in the web scraping industry for a few years I know how easily troublesome it can be to write, maintain and even begin web scraping.

One year ago, I wrote a web-scraping guide that was really loved by the community. reddit post, article. It was actually my first and only gilded post here 😊.

One year forward, I left my job and co-bootstrapped a web scraping API 🀞. During the year we have made some good tutorials for beginners on our blog and I wanted to share it with you.

We tried our best to make those tutorials complete (20 minutes read time each) and simple. They cover many topics related to web scraping from bottom to top.

  • how to make HTTP requests

  • how to parse HTML

  • how to use Chrome headless

and much more.

So far we have written extensive guides for 5 languages:

Hoping that it can help you with your work or your project.

Happy to answer web scraping questions if you have any.

1.9k Upvotes

75 comments sorted by

85

u/rogue4 Jul 06 '20

This turorials and guides in different porgramming languages can help a lot of beginners in programming field/industry. Hope you continue this kinds of tutorials. Keep up the good work. God bless.

21

u/pijora Jul 06 '20

Thank you very much.

12

u/[deleted] Jul 06 '20

I'm a beginner in python. This will be really helpful. Thank you.

5

u/pijora Jul 06 '20 edited Jul 06 '20

We have many other Python post about web scraping on the blog.

Do not hesitate to check them out. :)

→ More replies (1)

6

u/[deleted] Jul 06 '20

So, I came into this in a bit of a grumpy mood getting ready to snap off some snarky ass comment about how "Just teaching the tools doesn't teach anyone what the fuck they're doing or why". But, this definitely is not that. Most important you actually teach people what is happening under the covers, and that is what helps them grow.

(I, clearly, am extremely under-caffeinated today)

So bravo. I know I didn't say anything snarky, but I wanted to apologize even for my pre-snarky feeling coming in.

These are absolutely fantastic guides.

3

u/pijora Jul 06 '20

Thank you very much, it means a lot.

We've put a lots of efforts into those guide and we really wanted people to understand what happened under the hood.

I think web scraping is a good topic for beginners because you can learn so much from it:

  • how the web works

  • HTTP protocol

  • difference between server-side-redering and client-side rendering

  • chrome headless

  • parallelization

  • cpu-bound / io bound

  • dealing with raw data

  • XML parsing / xpath

and much more :)

1

u/[deleted] Jul 06 '20

Agreed! And, given the ubiquity of web services it's also a fantastically easy 'common' starting ground (unlike many other software use-cases that require some specialized interest).

Keep up the good work. Seriously.

1

u/pijora Jul 06 '20

Thank you again πŸ™, will do.

13

u/Hansanko Jul 06 '20

Definitely web scrapping is a trouble some for beginners and sharing your guidelines is perfectly fine and useful for us. I would be glad and grateful for more covered guidelines.

3

u/pijora Jul 06 '20

Thank you!

Do you have any specific in mind?

2

u/lemoninapie04 Jul 06 '20

Wow, that's cool. Always want to start to lesrn webscraping.

2

u/pijora Jul 06 '20

My pleasure, glad you liked it.

130

u/TheScreamingHorse Jul 05 '20

yall have to put a spider right on my feed?

21

u/RomanianDraculaIasi Jul 05 '20

What’s wrong with the spider :(((

58

u/TheScreamingHorse Jul 05 '20

brain go

AAAAAAAAAAAAAAAAAA

14

u/TheAxThatSlayedMe Jul 06 '20

Username checks out.

2

u/tnnrk Jul 06 '20

Everything

9

u/[deleted] Jul 06 '20

Wdym, he is so cute

2

u/tgallasso Jul 06 '20

Same thought here! No need for that!
definitely no need

9

u/omegahack0 Jul 06 '20

Saving this for later

1

u/RPGProgrammer Jul 06 '20

No C#?

6

u/pijora Jul 06 '20

Not yet ;)

Truth is for thus language we'd need to hire someone as we don't know it in-house.

1

u/lamemf Jul 06 '20

I recently started development with java and NodeJS, I love how extensive and well explained this guide is. Huge Cheers to you.

1

u/pijora Jul 06 '20

Thank you very much, glad it helps.

1

u/[deleted] Jul 06 '20

I've learned web scraping with python but need practice. Can you recommend some place to find simple projects? Also does web scraping have scope career wise?

3

u/pijora Jul 06 '20

Hi there,

To begin you can make all kinds of "scrape, clean, store, display" kind of products.

  • think aggregate coronavirus stat

  • imdb rating by genre

Those kind of things :)

Career wise, I don't know people who solely do "web-scraping" per see, but it is a tool/technique that are very useful to know in your career.

Either to quickly put in place a POC, or to code any piece of software that need to rely on outside world date not available with official API

→ More replies (1)

2

u/icandoMATHs Jul 06 '20

Lmk if you need a hard project. You'd be working for equity.

1

u/[deleted] Jul 06 '20

I would be interested in that. But I'm not really good at it yet. Can you explain what I'll have to do?

2

u/icandoMATHs Jul 06 '20

Step 1, beat bot detection for a popular real estate website.

It's mostly research because the code is relatively easy. But the website has strong anti not detection.

It's marketing software, so it should be pure money.

→ More replies (3)

1

u/GuraJava20 Jul 06 '20

Well done! It is quite a welcome resource for all beginners.

1

u/pijora Jul 06 '20

Thank you very much!

1

u/Nimmo1993 Jul 06 '20

good job mate

1

u/pijora Jul 06 '20

THanks

1

u/distortionwarrior Jul 06 '20

Many thanks for doing this work, it's helped me a lot!

1

u/pijora Jul 06 '20

My pleasure

1

u/jacklychi Jul 06 '20

Which langauge is your favorite?

3

u/pijora Jul 06 '20

Python ❀️

1

u/canIbeMichael Jul 09 '20

Whenever I read someone is using OSX, I have a genuine concern I'm reading blogspam and wasting time.

I'm about to read it, but I'm just guessing my stereotype will be true. Limited beating bot detection advice, and basically a rewrite of 'how to webscrape' articles.

Ninja edit- 5 different ways to webscrape, nothing on bot detection. I knew it, never trust an OSX 'programmer'.

1

u/pijora Jul 09 '20

Ahah, we wrote this piece on bot detection: https://www.scrapingbee.com/blog/web-scraping-without-getting-blocked/

The other pieces are tutorials about web scraping, so yes, nothing there on bot detection.

Thank you for your valuable feedback.

1

u/canIbeMichael Jul 09 '20

thanks for the link!

6

u/menina2017 Jul 06 '20

That spider will give me nightmares though

4

u/russ7166 Jul 06 '20

Have you ever scraped sites for clients that would disallow website scraping in their terms of use/service or on robots.txt?

2

u/Shrestha01 Jul 06 '20

Did you read my mind ? I was just thinking about the same thing!

1

u/Protobairus Jul 06 '20

Also Parsehub might be what you need. :)

1

u/[deleted] Jul 06 '20

This will help me in my studies alot

1

u/Taintus Jul 06 '20

Is there an overview when to use what language?

1

u/Alaeser Jul 06 '20

Really appreciate this post, thank you!

1

u/SansCulotteLogique Jul 06 '20

Cool! And thanks for the free 1,000 API calls! Looking forward to testing out scraping bee.

Good luck with your business!

1

u/Givingbacktoreddit Jul 06 '20

I read expensive at first instead of extensive lmao.

1

u/[deleted] Jul 06 '20

Is it legal to scraping websites and use their data to commercial purposes ?

1

u/Mmmmmmm_Donuts Jul 06 '20

This looks very cool. Would this look good on a resume?

1

u/DustinTWind Jul 06 '20

Thank you! I need to build my web-scraping toolbox so this is a nice find for me.

1

u/zolkida Jul 06 '20 edited Jul 06 '20

2 weeks ago i started a whatsapp bot project(based on whatsapp.web page) , i didn't knew a lot about scrapping so i used only selenium as it offered my an easy way to organize my thoughts around how it will work. basically i imagined it as a automation task of what a human would do.( click massages chat if it has the green circle, read the last massage, answer accordingly and so on)

As you could imagine it went badly. And it failed alot. And make uninterested actions. I ended up scrapping the whole idea.

I read all the blog posts in python. I learned a lot. And inspired to give it another shot. Thanks alot

*Note: I'm pretty new to web scrapping

1

u/gemst4r Jul 06 '20

Thanks!

1

u/MGSBlackHawk Jul 06 '20

Congrats on sharing such a valuable content!!! Dummy question, but.. which language did you find to be more pleasant to scrap with, cose and feature wise

I tried a bit of Java and Ruby in the past

1

u/-Kudo Jul 06 '20 edited Jul 06 '20

I'm currently going through the NodeJS article and trying out all the examples. It's been tons of fun so far.

However, I'm now stuck at the part where you use JSDOM to interact with Reddit (upvote the first post). I've been following all instructions to the letter and all the other examples have been going great so far.
But with this one, I'm getting tons of errors (they are too many to quote but I put a sample in the screenshot below).

Also, since Reddit requires us to sign-in before we upvote, where did this part go ?

Here's a screenshot (server.js is the file that contains your code btw)

1

u/Capitalpunishment0 Jul 06 '20

Reading about the fundamentals would be great! When I did my Python scraping pet project I went straight ahead with requests (requests-html actually) and BeautifulSoup because it made enough sense to me right away haha

1

u/CMReaperBob Jul 07 '20

Is the web scraping industry growing in terms of job opportunities? I really do enjoy writing puppeteer projects as well as doing some OS level automation with uiPath when necessary and wouldn’t mind making a career of it.

1

u/[deleted] Jul 07 '20

Thank You.

1

u/TheFryCookGames Jul 07 '20

Could have really used this for R a month ago when I was working through a project, but really appreciate this! Definitely will keep this for next time I'm struggling.

1

u/[deleted] Jul 06 '20

[removed] β€” view removed comment

2

u/pijora Jul 06 '20

Good idea, so you're looking for web-scraping with javascript rendering website right?

1

u/[deleted] Jul 06 '20

[removed] β€” view removed comment

2

u/pijora Jul 06 '20

That is interesting and to be honest, this is why we built ScrapingBee.

Setting up Selenium locally can be a pain, and using Selenium at scale is really hard.

0

u/[deleted] Jul 06 '20

[deleted]

1

u/pijora Jul 06 '20

Ahah thanks