3

On Facebook I want to find fb_dtsg to make a status:

import urllib, urllib2, cookielib
jar = cookielib.CookieJar() 
cookie = urllib2.HTTPCookieProcessor(jar)
opener = urllib2.build_opener(cookie)

data = urllib.urlencode({'email':"email",'pass':"password", "Log+In":"Log+In"})
req = urllib2.Request('http://www.facebook.com/login.php')
opener.open(req, data)
opener.open(req, data) #Needs to be opened twice to log on.

req2 = urllib2.Request("http://www.facebook.com/")
page = opener.open(req2)
fb_dtsg = page[page.find('name="fb_dtsg"') + 22:page.find('name="fb_dtsg"') + 33] #This just finds the value of "fb_dtsg".

Yes, this does find a value, and a value that looks like fb_dtsg would look like, but this value is always changing when I would open the webpage again and also when I would use it to make a status, it would not work, and when I would record what is happening on google chrome if I was making a status normally, I would get an working fb_dtsg value and it would not change (for a long session), and would work if I used it to try make a status. Please, please show me how I can fix this up without using the API.

user3818650
  • 581
  • 1
  • 7
  • 19

1 Answers1

4

The searching criteria to find fb_dtsg truncates last digit, so change 33 to 34

fb_dtsg = page[page.find('name="fb_dtsg"') + 22:page.find('name="fb_dtsg"') + 34]

Anyways you can use a better way of searching the fb_dtsg using re

re.findall('fb_dtsg.+?value="([^"]+)"',page)

As I answered in one of your early posts it may also require other hidden variables also. If this still doesn't work, can you provide the code where you are making the post including all the post form data

BTW sorry for not looking at all your previous posts with same content :P