Reputation: 2998
I'm using the requests module for python, and sending a GET request to a site as follows:
r = requests.get("https://www.youtube.com", params={"search_query":"Hello World"}).text
Which just returns the HTML of the page on YouTube that searches for "Hello World", which is the parameter for a field with the name "search_query".
However, let's say that one parameter I want to input does not have a name on the site, but is still part of the form.
The site I'm talking about has the following code:
<input type="text" id="youtube-url" value="http://www.youtube.com/watch?v=KMU0tzLwhBE" onclick="sALL(this)" autocomplete="off" style="width:466px;">
How would I go about sending a parameter to this specific input, considering it does not have a name?
Thanks
EDIT: The full HTML of the code:
Upvotes: 0
Views: 610
Reputation: 62868
This site doesn't do any normal submitting, everything is done via javascript. When you push the button a GET request is sent like this:
"/a/pushItem/?item=" + escape(g("youtube-url").value)
+ "&el=na&bf=" + getBF()
+ "&r="+ (new Date()).getTime();
Then with the result of this, another is sent:
"/a/itemInfo/?video_id=" + video_id + "&ac=www&t=grp&r=" + a.getTime();
So in python you can try this:
import time
videoid = requests.get("http://www.youtube-mp3.org/a/pushItem/",
params={
"item": "your youtube video url",
"el": "na",
"bf": "false",
"r": int(time.time() * 1000000) # JS timestamps are in microseconds
}).text
info = requests.get("http://www.youtube-mp3.org/a/itemInfo/",
params={
"video_id": videoid,
"ac": "www",
"t": "grp",
"r": int(time.time() * 1000000)
}).text
And then you'll have to parse the info
, which isn't even JSON, but more javascript, and do whatever you want with that data.
You might have to deal with CAPTCHAs or conversion progress.
Upvotes: 1