DEV Community

Discussion on: Get your first dev job by building these projects! #2: Markov Chain Lyrics Generator

Collapse
 
ianainslie profile image
ianainslie • Edited

Hi. I love this and have a few ideas for adding my own twists on it.
However, using Jupyter Notebook, I get as far as the end of Step 3 - with a nice list of URLs. When I go into Step 4, I get hit with "HTTPError: HTTP Error 403: Forbidden".
I take this to mean that the site is not happy with the bot activity. How do I incorporate a User=Agent into the code to circumvent this? I know how to do this with the requests library, but this is my first time with the urllib library and I am struggling a little :)
Would love your input on this, as it's such a cool looking little project that I would love to complete
Thanks, Ian

Collapse
 
catmcgeecode profile image
Cat McGee

Hi Ian, yeah unfortunately this happens. If you look at the GItHub repo, somebody actually merged a PR to help with that.

You can use sleep from Python's time module, and sleep for random intervals while you scrape the lyrics. That way AZLyrics doesn't pick up that you are a bot.

Fortunately, after getting the lyrics you don't have to run it again so you can avoid the ban!

Collapse
 
ianainslie profile image
ianainslie • Edited

Hi Cat, I just wanted to pop by and say thanks again. I decided to make a few changes to your original code:

  • Rewrote most of it to use BeautifulSoup, as I understand that module better
  • Dropped the Markov chains, as they were not really working for me. Made more use of the random module
  • Created a GUI (which in turn lead to me learning a tonne of stuff about TKinter)

I am now working on a new project and was just wondering how many do employees like to see in a portfolio for entry level software engineers?
Also, does blogging about projects help in gaining employment? I have my own site (ianainslie.uk), so that would be easy to initiate if worthwhile.
Lastly, thanks again for the whole 2.20 videos thing - it lit a fire under my arse to make the transition from tutorial watcher to project maker.