Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In blog by Grant Curell of "Python – Search Youtube for Video", I got the code that gives the link of youtube video. But when I am using it, it gives me an error. Why?

Please tell me if there is something wrong here.

What I have tried:

Here is the code which I copied -
import urllib.request
import urllib.parse
import re

query_string = urllib.parse.urlencode({"search_query" : input()})
html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
print("http://www.youtube.com/watch?v=" + search_results[0])
Posted
Updated 1-Jul-20 0:11am
v2
Comments
Richard MacCutchan 1-Jul-20 5:38am    
What error?
Kornfeld Eliyahu Peter 1-Jul-20 6:09am    
It gives me an error too...

1 solution

If you got the code from a blog, then the author of the blog is the obvious person to ask, not a random website that has no idea what the blog involves.

Since this blog is hosted here, you will find a forum at teh bottom in which you can talk to the author: Python – Search Youtube for Video[^]

Give him some time: remember his timezone may be very different from yours, and he may also be busy - I'm sure he will get back to you if you are patient.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900