How to send parameters with a GET request?

22,033

Solution 1

Looking at youtube, the url to the search page seems to be

http://www.youtube.com/results?search_query=test

You're missing the results part, which is the page you are looking for.

Solution 2

Use the Youtube API to get the data.

# Import the modules
import requests
import json

# Make it a bit prettier..
print "-" * 30
print "This will show the Most Popular Videos on YouTube"
print "-" * 30

# Get the feed
r = requests.get("http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?v=2&alt=jsonc")
r.text

# Convert it to a Python dictionary
data = json.loads(r.text)

# Loop through the result. 
for item in data['data']['items']:

    print "Video Title: %s" % (item['title'])

    print "Video Category: %s" % (item['category'])

    print "Video ID: %s" % (item['id'])

    print "Video Rating: %f" % (item['rating'])

    print "Embed URL: %s" % (item['player']['default'])

    print

Go through http://www.pythonforbeginners.com/python-on-the-web/using-the-youtube-api/ for more details.

Solution 3

Try this to see what you are actually submitting print r.url

Share:
22,033
Cisplatin
Author by

Cisplatin

Updated on July 08, 2020

Comments

  • Cisplatin
    Cisplatin almost 4 years

    I'm currently trying to make a GET request to YouTube, to search for a video on it (using Python, as well as the Requests module). The following is what I'm doing to make a request:

    r = requests.get("http://www.youtube.com/", 
            params={
                "search_query": "Test"
            }).text
    

    However, when printing the request, it only seems to be getting the homepage of YouTube, no matter what I change the search query to.

    Would anyone know why this is occuring?

    Thanks