r/code • • Feb 13 '20

Can someone help me understand how to “scrape” a site?

Hi. I’ve always been fascinated by Twitter bots but only recently did I write one in Python and I think I’d like to again. However, for this idea I was hoping I could scrape lyrics off Genius? I understand the purpose and need for scraping, but I’ve always been confused by what the process actually is? How is it “scraping” this data from a site?

9 Upvotes

3 comments sorted by

3

u/PoliticalSeahorse Feb 13 '20

Scraping is basically extracting the html page and then manipulating it. You will get the whole page and let's say you just want the lyrics, you will have to select the html element (with XPath, CSS Selectors...) to retrieve the data you want.

You can do pretty much what you want but while scraping you need to be careful about things like Crawl-Delay, Allow and Disallow urls, your User Agent and other things... I suggest that you follow some tutorials about Scraping ( https://www.youtube.com/watch?v=2vcp0fKq3aw is a pretty good one about Scrapy).

If you take a look at https://genius.com/robots.txt you can see what URL they disallow.

And in Python you have a lot of good scraping libs like Requests mixed with Beautiful Soup.

Have a nice day !

2

u/14bux Feb 13 '20

Thanks a bunch!!! This is a huge help 🙏

3

u/malicart Feb 13 '20

Simplified Version: Writing code that goes to the site and based on specific html sections copies (scrapes) the data you are looking for. This can be against the TOS of some sites, and depending on how you do it can get you blocked.