Abul Hasnat Abul Hasnat - 1 year ago 214
Python Question

Curl POST in python or similar method

This might be a little too much direct question. New to Python

I am trying to Parse/Scrape video link from a video website(Putlocker).

Ie http://www.putlocker.com/file/A189D40E3E612C50.

The page comes up initially with this code below or similar

<form method="post">
<input type="hidden" value="3d0865fbb040e670" name="hash">
<input name="confirm" type="submit" value="Continue as Free User"
id="submitButton" class="confirm_button" style="width:190px;">

value="3d0865fbb040e670" Changes everytime...

Import urllib
import urllib2

url = 'http://www.putlocker.com/file/A189D40E3E612C50.'
response = urllib2.urlopen(url)
page = response.read()

from here i find the Value="?" of Hash


url = 'http://www.putlocker.com/file/A189D40E3E612C50.'
values = {'hash' : 3d0865fbb040e670}
data = urllib.urlencode(values)
response = urllib2.urlopen(url)
page = response.read()

But I end up on same page again. Do I post value="Continue as Free User" as well?
How do I go ahead with posting both data.

A working code would be helpful.
I am trying hard but no avail yet.

Ok..after the suggestion made by few programmers

I tried with codes like below

url = 'http://www.putlocker.com/file/A189D40E3E612C50'
response = urllib2.urlopen(url)
html = response.read()
r = re.search('value="([0-9a-f]+?)" name="hash"', html)
session_hash = r.group(1)
print session_hash
form_values = {}
form_values['hash'] = session_hash
form_values['confirm'] = 'Continue as Free User'
data = urllib.urlencode(form_values)
response = urllib2.urlopen(url, data=data)
html = response.read()
print html

So I am returned with same page again again..What am I doing wrong here!! I have seen something called pycurl..but I want use something simpler..Any clue??

Answer Source


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download