Dealing with timeout error while web scraping - python-3.x

The link i am trying to scrape is https://www.zomato.com/lucknow/skyhilton-1-alambagh/reviews specifically the 'Names' and 'Reviews'.
I keep getting the timeout error while requesting the url, i haven't defined the timeout limit in this case. Is there a way to make my request more manageable or should i use some other libraries/modules for this purpose.
Error message : ' TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond '
Here is my code:
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
from urllib.request import Request
url = 'https://www.zomato.com/lucknow/skyhilton-1-alambagh/reviews'
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
uClient = uReq(req)
page = uClient.read()
page_html = soup(page, "html.parser")
containers = page_html.findAll("div",{"class":"sc-eetwQk hAcPWO"})
print(soup.pretiffy(containers[0]))

import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
}
params = {
'sort': 'dd',
'filter': 'reviews-dd',
'res_id': 18439027
}
def main(url):
with requests.Session() as req:
for page in range(1, 11):
print(f"{'*' * 30} Extracting Page# {page} {'*' * 30}")
params['page'] = page
r = req.get(url, params=params, headers=headers).json()
for x in r['entities']['REVIEWS'].values():
print("Username: {:<20}, Comment: {}".format(
x['userName'], x['reviewText']))
main("https://www.zomato.com/webroutes/reviews/loadMore")
Output:
****************************** Extracting Page# 1 ******************************
Username: Nitisha Dwivedi , Comment: I tried veg manchurian, veg noodles, pasta arrabiata, virgin mojito from sky hilton and the food was great, freshly cooked, very tasty and well presented. The waiters were attentive and service was overall good but some of the waiters are rude even. I would suggest you to come to this place and enjoy food!
Username: Sakshi Jaiswal , Comment: this place is lovely rocking<br/>the party place <br/>best saturday place<br/>live music great taste<br/><br/>
Username: Atul , Comment: They send me gravy chicken while I ordered tava chicken listed under DRY snacks and beforehand informed Mr. Dinesh Dixit as well about the order.But this is what I received. Gravy can be clearly seen with Oil spilling all over. When I informed ZOMATO and the manager about it, ZOMATO said they will give the feedback to the restaurant (unsatisfactory resolution) and the manager said this is how dry tava chicken looks like. Do not order online as no one will listen to you even if you are right . Pathetic experience from SkyHilton and ZOMATO as well this time.
Username: Sweety Singh , Comment:
Username: Aman Bhardwaj , Comment: the food is awesome you can even visit here with your family the taste of food is ❤️❤️❤️
****************************** Extracting Page# 2 ******************************
Username: Akanksha Singh , Comment:
Username: Harsh Mehrotra , Comment:
Username: Sheetal Kapoor , Comment: I have given them 4 stars because of the service as the restaurant need to really work upon that. <br/>
Username: Mâñvéñdrâ Singh , Comment:
Username: Vishal Yadav , Comment: Good food
****************************** Extracting Page# 3 ******************************
Username: Avni Singh , Comment:
Username: AVNI SINGH , Comment:
Username: Avni Singh , Comment:
Username: Vanshika Shukla , Comment:
Username: Anushka Singh , Comment:
****************************** Extracting Page# 4 ******************************
Username: Anushka Singh , Comment:
Username: Priya Singh , Comment:
Username: Chandramohan Yadav , Comment: Staff and ambience is too good and a healthy and friendly environment
Username: Kavita Vishwakarma , Comment:
Username: Govind Bahadur , Comment: Good food good taste all time to choose this place for ordering and dining very good place and serve very good
****************************** Extracting Page# 5 ******************************
Username: Govind Bahadur , Comment: Such a recommended place to all.<br/>Here food serve good with hygiene way and with a superior good taste.
Username: Anuj Kashyap , Comment: My friend was suggested me to order from here and i verry surprised by there taste and food quality.<br/>Thank you Sky Hilton to serve us verry well.
Username: Anuj Kashyap , Comment: My friend was suggested me to order from here and i verry surprised by there taste and food quality.<br/>Thank you Sky Hilton to serve us verry well.
Username: Akash Choubey , Comment: Good food and very good taste my friend was suggested to order from here and I will totally appreciate the food taste and hygiene packing 😋😋
Username: Akshat Anand , Comment: fine dine restaurant is very excellent and the service person is very kind ; dheer singh who is so amazing and overall experience is very amazing
****************************** Extracting Page# 9 ******************************
Username: Anushree Nigam , Comment: Dheer was very courteous while serving!
Username: Agosh Baranwal , Comment: Amazing staff. Very dedicated and polite.
Username: Sameer Agarwal , Comment:
Username: Vinod Kushwaha , Comment: Awesome food and service by Dheer singh
Username: Manendra Singh , Comment: Nice ambiance music was soo good i love skyhilton exxillent service given by ajeet patel
****************************** Extracting Page# 10 ******************************
Username: Vandana Singh , Comment: awesome service very nice food 🎎🎎🎎🎎🎎🎎🎎🎎<br/>Service dheer singh
Username: Harpreet Singh , Comment: Best service by shubham kanchan
Username: Shruti Mirchandani , Comment: Heard about this restaurant cum bar as one of the trending outlet in Lucknow in Alambagh.<br/>Can visit for good food simply served in very simple way have tried Handi Mutton, Pasta, Paneer Tikka Masala, jeera rice and of course drinks.<br/><br/>Paneer tikka masala is actually good not like any other restaurant who put All that capsicum and onion in paneer tikka masala it's blend of flavor full masala and taste good.<br/><br/>Handi masala was also tasted good.<br/><br/>Though didn't like the ambience at all as it could be done better.<br/><br/>Also can eenjoy Hukka in open sitting area at fifth floor.
Username: Anmol Kacker , Comment: I am writing this review after my fourth visit to this place. Rest all my visits were on a weekday afternoon so, decided to give this place a try on a Saturday night.<br/>The ambiance though a lot changed than before, was good but that's pretty much it. The music was way too loud and deafening. They are currently having a street food festival
so, decided to try a couple of items. Vada pav and omelette were the items ordered. Despite repeatedly telling the person who took the order to give a masala omelette, he got a plain one and that too cold. The crispy corn ordered was awful. Sweet corn soup, was simply cold water with some half boiled vegetables and traces of corn. It had just no taste at all. Tried finishing the items, unfortunately, couldn't even eat half of the meal.<br/>Finally, decided to get up and walk away. Saturday nights can be maddening with overflowing crowd but atleast do something about your food. Quick service stands nowhere if what you are delivering is so bad. Really thought the place would be a bit different this time. Unfortunately, it was as bad as before. Done with this place ! Never again !<br/><br/>Also, I am not big a fan of saturday night parties but all I have to say here is that people were coming in, looking around and walking away. Seeing heavily drunken men dancing is not what a saturday night means to me or I guess to anyone.
Username: Piyush Kumar , Comment: Please increase the salary of mr. Bhanu he is good in f&b Service skills

Related

is there a method to detect person and associate a text?

I have a text like :
Take a loot at some of the first confirmed Forum speakers: John
Sequiera Graduated in Biology at Facultad de Ciencias Exactas y
Naturales,University of Buenos Aires, Argentina. In 2004 obtained a
PhD in Biology (Molecular Neuroscience), at University of Buenos
Aires, mentored by Prof. Marcelo Rubinstein. Between 2005 and 2008
pursued postdoctoral training at Pasteur Institute (Paris) mentored by
Prof Jean-Pierre Changeux, to investigate the role of nicotinic
receptors in executive behaviors. Motivated by a deep interest in
investigating human neurological diseases, in 2009 joined the
Institute of Psychiatry at King’s College London where she performed
basic research with a translational perspective in the field of
neurodegeneration.
Since 2016 has been chief of instructors / Adjunct professor at University of Buenos Aires, Facultad de Ciencias Exactas y Naturales.
Tom Gonzalez is a professor of Neuroscience at the Sussex Neuroscience, School of Life Sciences, University of Sussex. Prof.
Baden studies how neurons and networks compute, using the beautiful
collection of circuits that make up the vertebrate retina as a model.
I want to have in output :
[{"person" : "John Sequiera" , "content": "Graduated in Biology at Facultad...."},{"person" : "Tom Gonzalez" , "content": "is a professor of Neuroscience at the Sussex..."}]
so we want to get NER : PER for person and in content we put all contents after detecting person until we found a new person in the text ...
it is possible ?
i try to use spacy to extract NER , but i found a difficulty to get content :
import spacy
​
nlp = spacy.load("en_core_web_lg")
doc = nlp(text)
​
for ent in doc.ents:
print(ent.text,ent.label_)

How can i get the asin of this string using regex?

Hi I have the following string, how can I get the B000RMTGUQ of this entire string using regex pytnon?
{'asin': 'B000RMTGUQ', 'imUrl': 'http://ecx.images-amazon.com/images/I/515KlX4dEUL._BO2,204,203,200_PIsitb-sticker-v3-big,TopRight,0,-55_SX278_SY278_PIkin4,BottomRight,1,22_AA300_SH20_OU01_.jpg', 'related': {'also_bought': ['B009QJMXI8', 'B00CNQ7MJG']}, 'categories': [['Books', 'History', 'World', 'Jewish', 'Holocaust'], ['Books', 'History', 'World', 'Religious', 'Judaism'], ['Books', 'Politics & Social Sciences', 'Social Sciences'], ['Books', 'Religion & Spirituality', 'Judaism'], ['Kindle Store', 'Kindle eBooks', 'History', 'World', 'Jewish', 'Holocaust'], ['Kindle Store', 'Kindle eBooks', 'Politics & Social Sciences', 'Social Sciences'], ['Kindle Store', 'Kindle eBooks', 'Religion & Spirituality', 'Judaism']], 'description': "Kibbutz Buchenwald was founded in Germany in 1945 by 16 survivors of Buchenwald concentration camp. The Zionist training farm was organized to prepare Jews for emigration to Palestine. One of the founders was Yeohezkel Tydor, the author's father, who died in 1993. Baumel's narration of the kibbutz's history is divided into two sections. Part one examines the kibbutz from its creation until the departure of the founding group to Palestine in late summer 1945. Part two traces the kibbutz's subsequent history in Palestine and Germany, from the autumn of 1945 until the mid-1950s. Kibbutz Buchenwald was abolished in Germany in 1948; the kibbutz as it was founded in what is now Israel--named Netzer Sereni--still exists today. The story of these pioneers and their physical, psychological, ideological, and political struggles forms the nucleus of this absorbing book.George Cohen"}
You could use json to parse your string to a valid dictionary:
First note that a valid json is enclosed by double quotes. Also, note that author"s etc need single quotes. Hence you could do:
import json, re
dct = json.loads(re.sub('"s', "'s", re.sub("'", '"', string)))
dct['asin']
'B000RMTGUQ'
EDIT
from the comments below, it seems you do not have a json string but rather a valid python dictionary in string format:
therefore you could directly do:
dc = eval(string)
dc['asin']
Futher more consider using ast.literal_eval rather than eval.
data
string = """{'asin': 'B000RMTGUQ', 'imUrl': 'http://ecx.images-amazon.com/images/I/515KlX4dEUL._BO2,204,203,200_PIsitb-sticker-v3-big,TopRight,0,-55_SX278_SY278_PIkin4,BottomRight,1,22_AA300_SH20_OU01_.jpg', 'related': {'also_bought': ['B009QJMXI8', 'B00CNQ7MJG']}, 'categories': [['Books', 'History', 'World', 'Jewish', 'Holocaust'], ['Books', 'History', 'World', 'Religious', 'Judaism'], ['Books', 'Politics & Social Sciences', 'Social Sciences'], ['Books', 'Religion & Spirituality', 'Judaism'], ['Kindle Store', 'Kindle eBooks', 'History', 'World', 'Jewish', 'Holocaust'], ['Kindle Store', 'Kindle eBooks', 'Politics & Social Sciences', 'Social Sciences'], ['Kindle Store', 'Kindle eBooks', 'Religion & Spirituality', 'Judaism']], 'description': "Kibbutz Buchenwald was founded in Germany in 1945 by 16 survivors of Buchenwald concentration camp. The Zionist training farm was organized to prepare Jews for emigration to Palestine. One of the founders was Yeohezkel Tydor, the author's father, who died in 1993. Baumel's narration of the kibbutz's history is divided into two sections. Part one examines the kibbutz from its creation until the departure of the founding group to Palestine in late summer 1945. Part two traces the kibbutz's subsequent history in Palestine and Germany, from the autumn of 1945 until the mid-1950s. Kibbutz Buchenwald was abolished in Germany in 1948; the kibbutz as it was founded in what is now Israel--named Netzer Sereni--still exists today. The story of these pioneers and their physical, psychological, ideological, and political struggles forms the nucleus of this absorbing book.George Cohen"}"""

How to reconstruct original text from spaCy tokens, even in cases with complicated whitespacing and punctuation

' '.join(token_list) does not reconstruct the original text in cases with multiple whitespaces and punctuation in a row.
For example:
from spacy.tokenizer import Tokenizer
from spacy.lang.en import English
nlp = English()
# Create a blank Tokenizer with just the English vocab
tokenizerSpaCy = Tokenizer(nlp.vocab)
context_text = 'this is a test \n \n \t\t test for \n testing - ./l \t'
contextSpaCyToksSpaCyObj = tokenizerSpaCy(context_text)
spaCy_toks = [i.text for i in contextSpaCyToksSpaCyObj]
reconstruct = ' '.join(spaCy_toks)
reconstruct == context_text
>False
Is there an established way of reconstructing original text from spaCy tokens?
Established answer should work with this edge case text (you can directly get the source from clicking the 'improve this question' button)
" UNCLASSIFIED U.S. Department of State Case No. F-2014-20439 Doc No. C05795279 Date: 01/07/2016\n\n\n RELEASE IN PART\n B5, B6\n\n\n\n\nFrom: H <hrod17#clintonemail.com>\nSent: Monday, July 23, 2012 7:26 AM\nTo: 'millscd #state.gov'\nCc: 'DanielJJ#state.gov.; 'hanleymr#state.gov'\nSubject Re: S speech this morning\n\n\n\n Waiting to hear if Monica can come by and pick up at 8 to take to Josh. If I don't hear from her, can you send B5\nsomeone else?\n\n Original Message ----\nFrom: Mills, Cheryl D [MillsCD#state.gov]\nSent: Monday, July 23, 2012 07:23 AM\nTo: H\nCc: Daniel, Joshua J <Daniel1.1#state.gov>\nSubject: FW: S speech this morning\n\nSee below\n\n B5\n\ncdm\n\n Original Message\nFrom: Shah, Rajiv (AID/A) B6\nSent: Monday, July 23, 2012 7:19 AM\nTo: Mills, Cheryl D\nCc: Daniel, Joshua.'\nSubject: S speech this morning\n\nHi cheryl,\n\nI look fwd to attending the speech this morning.\n\nI had one last minute request - I understand that in the final version there is no reference to the child survival call to\naction, but their is a reference to family planning efforts. Could you and josh try to make sure there is some specific\nreference to the call to action?\n\nAlso, in terms of acknowledgements it would be good to note torn friedan's leadership as everyone is sensitive to our ghi\ntransition and we want to continue to send the usaid-pepfar-cdc working together public message. I don't know if he is\nthere, but wanted to flag.\n\nLook forward to it.\n\nRaj\n\n\n\n\n UNCLASSIFIED U.S. Department of State Case No. F-2014-20439 Doc No. C05795279 Date: 01/07/2016\n\x0c"
You can very easily accomplish this by changing two lines in your code:
spaCy_toks = [i.text + i.whitespace_ for i in contextSpaCyToksSpaCyObj]
reconstruct = ''.join(spaCy_toks)
Basically, each token in spaCy knows whether it is followed by whitespace or not. So you call token.whitespace_ instead of joining them on space by default.

unable to get rid of all emojis

I need help removing emojis. I looked at some other stackoverflow questions and this is what I am de but for some reason my code doesn't get rid of all the emojis
d= {'alexveachfashion': 'Fashion Style * Haute Couture * Wearable Tech * VR\n👓👜⌚👠\nSoundCloud is Live #alexveach\n👇New YouTube Episodes ▶️👇', 'andrewvng': 'Family | Fitness | Friends | Gym | Food', 'runvi.official': 'Accurate measurement via SMART insoles & real-time AI coaching. Improve your technique & BOOST your performance with every run.\nSoon on Kickstarter!', 'triing': 'Augmented Jewellery™️ • Montreal. Canada.', 'gedeanekenshima': 'Prof na Etec Albert Einstein, Mestranda em Automação e Controle de Processos, Engenheira de Controle e Automação, Técnica em Automação Industrial.', 'jetyourdaddy': '', 'lavonne_sun': '☄️🔭 ✨\n°●°。Visual Narrative\nA creative heart with a poetic soul.\n————————————\nPARSONS —— Design & Technology', 'taysearch': 'All the World’s Information At Your Fingertips. (Literally) Est. 1991🇺🇸 🎀#PrincessofSearch 🔎Sample 👇🏽 the Search Engine Here 🗽', 'hijewellery': 'Fine 3D printed jewellery for tech lovers #3dprintedjewelry #wearabletech #jewellery', 'yhanchristian': 'Estudante de Engenharia, Maker e viciado em café.', 'femka': 'Fashion Futurist + Fashion Tech Lab Founder #technoirlab + Fashion Designer / Parsons & CSM Grad / Obsessed with #fashiontech #future #cryptocurrency', 'sinhbisen': 'Creator, TRiiNG, augmented jewellery label ⭕️ Transhumanist ⭕️ Corporeal cartographer ⭕️', 'stellawearables': '#StellaWearables ✉️Info#StellaWearables.com Premium Wearable Technology That Monitors Personal Health & Environments ☀️🏝🏜🏔', 'ivoomi_india': 'We are the manufacturers of the most innovative technologies and user-friendly gadgets with a global presence.', 'bgutenschwager': "When it comes to life, it's all about the experience.\nGoogle Mapper 🗺\n360 Photographer 📷\nBrand Rep #QuickTutor", 'storiesofdesign': 'Putting stories at the heart of brands and businesses | Cornwall and London | #storiesofdesign', 'trume.jp': '草創期から国産ウオッチの製造に取り組み、挑戦を続けてきたエプソンが世界に放つ新ブランド「TRUME」(トゥルーム)。目指すのは、最先端技術でアナログウオッチを極めるブランド。', 'themarinesss': "I didn't choose the blog life, the blog life chose me | Aspiring Children's Book Author | www.slayathomemum.com", 'ayowearable': 'The world’s first light-based wearable that helps you sleep better, beat jet lag and have more energy! #goAYO Get yours at:', 'wearyourowntechs': 'Bringing you the latest trends, Current Products and Reviews of Wearable Technology. Discover how they can enhance your Life and Lifestyle', 'roxfordwatches': 'The Roxford | The most stylish and customizable fitness smartwatch. Tracks your steps/calories/dist/sleep. Comes with FOUR bands, and a travel case!', 'playertek': "Track your entire performance - every training session, every match. \nBecause the best players don't hide.", '_kate_hartman_': '', 'hmsmc10': 'Health & Wellness 🍎\nBoston, MA 🏙\nSuffolk MPA ‘17 🎓 \n.\nJust Strong Ambassador 🏋🏻\u200d♀️', 'gadgetxtreme': 'Dedicated to reviewing gadgets, technologies, internet products and breaking tech news. Follow us to see daily vblogs on all the disruptive tech..', 'freedom.journey.leader': '📍MN\n🍃Wife • Homeschooling Mom to 5 🐵 • D Y I lover 🔨 • Small town living in MN. 🌿 \n📧Ashleybp5#gmail.com \n#homeschool #bossmom #builder #momlife', 'arts_food_life': 'Life through my phone.', 'medgizmo': 'Wearable #tech: #health #healthcare #wellness #gadgets #apps. Images/links provided as information resource only; doesn’t mean we endorse referenced', 'sawearables': 'The home of wearable tech in South Africa!\n--> #WearableTech #WearableTechnology #FitnessTech Find your wearable #', 'shop.mercury': 'Changing the way you charge.⚡️\nGet exclusive product discounts, and help us reach our goal below!🔋', 'invisawear': 'PRE-ORDERS NOW AVAILABLE! Get yours 25% OFF here: #girlboss #wearabletech'}
for key in d:
print("---with emojis----")
print(d[key])
print("---emojis removed----")
x=''.join(c for c in d[key] if c <= '\uFFFF')
print(x)
output example
---with emojis----
📍MN
🍃Wife • Homeschooling Mom to 5 🐵 • D Y I lover 🔨 • Small town living in MN. 🌿
📧Ashleybp5#gmail.com
#homeschool #bossmom #builder #momlife
---emojis removed----
MN
Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN.
Ashleybp5#gmail.com
#homeschool #bossmom #builder #momlife
---with emojis----
Changing the way you charge.⚡️
Get exclusive product discounts, and help us reach our goal below!🔋
---emojis removed----
Changing the way you charge.⚡️
Get exclusive product discounts, and help us reach our goal below!
There is no technical definition of what an "emoji" is. Various glyphs may be used to render printable characters, symbols, control characters and the like. What seems like an "emoji" to you may be part of normal script to others.
What you probably want to do is to look at the Unicode category of each character and filter out various categories. While this does not solve the "emoji"-definition-problem per se, you get much better control over what you are actually doing without removing, for example, literally all characters of languages spoken by 2/3 of the planet.
Instead of filtering out certain categories, you may filter everything except the lower- and uppercase letters (and numbers). However, be aware that ꙭ is not "the googly eyes emoji" but the CYRILLIC SMALL LETTER DOUBLE MONOCULAR O, which is a normal lowercase letter to millions of people.
For example:
import unicodedata
s = "🍃Wife • Homeschooling Mom to 5 🐵 • D Y I lover 🔨 • Small town living in MN. 🌿"
# Just filter category "symbol"
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', ))
print(t)
...results in
Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN.
This may not be emoji-free enough, yet the • is technically a form of punctuation. So filter this as well
# Filter symbols and punctuations. You may want 'Cc' as well,
# to get rid of control characters. Beware that newlines are a
# form of control-character.
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', 'Po'))
print(t)
And you get
Wife Homeschooling Mom to 5 D Y I lover Small town living in MN

Scraping youtube playlist

I've been trying to write a python script which will fetch me the name of the songs contained in the playlist whose link will be provided. for eg.https://www.youtube.com/watch?v=foE1mO2yM04&list=RDGMEMYH9CUrFO7CfLJpaD7UR85wVMfoE1mO2yM04 from the terminal.
I've found out that names could be extracted by using "li" tag or "h4" tag.
I wrote the following code,
import sys
link = sys.argv[1]
from bs4 import BeautifulSoup
import requests
req = requests.get(link)
try:
req.raise_for_status()
except Exception as exc:
print('There was a problem:',exc)
soup = BeautifulSoup(req.text,"html.parser")
Then I tried using li-tag as:
i=soup.findAll('li')
print(type(i))
for o in i:
print(o.get('data-video-title'))
But it printed "None" those number of time. I belive it is not able to reach those li tags which contains data-video-title attribute.
Then I tried using div and h4 tags as,
for i in soup.findAll('div', attrs={'class':'playlist-video-description'}):
o = i.find('h4')
print(o.text)
But nothing happens again..
import requests
from bs4 import BeautifulSoup
url = 'https://www.youtube.com/watch?v=foE1mO2yM04&list=RDGMEMYH9CUrFO7CfLJpaD7UR85wVMfoE1mO2yM04'
data = requests.get(url)
data = data.text
soup = BeautifulSoup(data)
h4 = soup.find_all("h4")
for h in h4:
print(h.text)
output:
Mike Posner - I Took A Pill In Ibiza (Seeb Remix) (Explicit)
Alan Walker - Faded
Calvin Harris - This Is What You Came For (Official Video) ft. Rihanna
Coldplay - Hymn For The Weekend (Official video)
Jonas Blue - Fast Car ft. Dakota
Calvin Harris & Disciples - How Deep Is Your Love
Galantis - No Money (Official Video)
Kungs vs Cookin’ on 3 Burners - This Girl
Clean Bandit - Rockabye ft. Sean Paul & Anne-Marie [Official Video]
Major Lazer - Light It Up (feat. Nyla & Fuse ODG) [Remix] (Official Lyric Video)
Robin Schulz - Sugar (feat. Francesco Yates) (OFFICIAL MUSIC VIDEO)
DJ Snake - Middle ft. Bipolar Sunshine
Jonas Blue - Perfect Strangers ft. JP Cooper
David Guetta ft. Zara Larsson - This One's For You (Music Video) (UEFA EURO 2016™ Official Song)
DJ Snake - Let Me Love You ft. Justin Bieber
Duke Dumont - Ocean Drive
Galantis - Runaway (U & I) (Official Video)
Sigala - Sweet Lovin' (Official Video) ft. Bryn Christopher
Martin Garrix - Animals (Official Video)
David Guetta & Showtek - Bad ft.Vassy (Lyrics Video)
DVBBS & Borgeous - TSUNAMI (Original Mix)
AronChupa - I'm an Albatraoz | OFFICIAL VIDEO
Lilly Wood & The Prick and Robin Schulz - Prayer In C (Robin Schulz Remix) (Official)
Kygo - Firestone ft. Conrad Sewell
DEAF KEV - Invincible [NCS Release]
Eiffel 65 - Blue (KNY Factory Remix)
Ok guys, I have figured out what was happening. My code was perfect and it works fine, the problem was that I was passing the link as an argument from the terminal and co-incidentally, the link contained some symbols which were interpreted in some other fashion for eg. ('&').
Now I am passing the link as a string in the terminal and everything works fine. So dumb yet time-consuming mistake.

Resources