[python-win32] Problem with Python win32com while loading facebook homepage

Adrien LEMAIRE lemaire.adrien at gmail.com
Fri Jul 24 15:18:43 CEST 2009


Hi dear members of the python-win32 python mailing list,

I'm trying to connect to my facebook account.. I'd like to automate some
tasks like closing applications requests, and why not automate task for
application games of facebook, if I arrive to do this.

But I can't arrive to connect to homepage..
First, without win32com, the code page return by the script was a javascript
script :

> <script type="text/javascript">
> (function(loc) { if (loc.pathname == '/') { return; } var uri_re =
> /^(?:(?:[^:\/?#]+):)?(?:\/\/(?:[^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/;
> var target_domain = ''; loc.href.replace(uri_re, function(all, path, query,
> frag) { var dst, src; dst = src = path + (query ? '?' + query : ''); if
> (frag) { if (frag.charAt(0) == '/') { dst = frag.replace(/^\/+/, '/')
> .replace(/_fb_qsub=([^&]+)&?/, function(all, domain){ if
> (domain.substring(domain.length - 13) == '.facebook.com') { target_domain
> = 'http://'+domain; } return ''; }); } else if (/&|=/.test(frag)) { var q
> = {}; var m = frag.match(/([^#]*)(#.*)?/); var arr =
> (query||'').split('&').concat((m[1]||'').split('&')); for (var i=0,
> length=arr.length; i<length; i++) { var t = arr[i].split('='); if (t.length
> && t[0] != '') { q[t[0]] = t[1]; } } var s = []; for (var i in q) {
> s.push(i+ (q[i]?'='+q[i]:'')); } dst = path+'?'+s.join('&')+(m[2]||''); } }
> dst = "" + dst; if (dst != src) { window.location.replace(target_domain +
> dst); } }); })(window.location);
> </script>
> <script>window.location.replace("http:\/\/www.facebook.com
> \/common\/browser.php");</script>
>


After reading a little on the web ( I searched a solution to execute
javascript code from python), I've found the next added lines, which use
win32com. I have installed pywin32-214 (I use python 2.6.2).

See below my code :

> # -*- coding:Utf-8 -*-
> #!/usr/bin/python
> import httplib
> import urllib
>
> Connexion = httplib.HTTP('www.facebook.com')
> Connexion.putrequest('GET', '/home.php')
> Connexion.putheader('Host', 'www.facebook.com')
> Connexion.putheader('Accept', 'text/html')
> Connexion.putheader('Cookie', 'the_long_cookie_from_facebook')
> Connexion.endheaders()
> ErrCode, ErrMsg, Headers = Connexion.getreply()
> Handle = Connexion.getfile()
> Buffer = Handle.read()
>
> from win32com.client.gencache import EnsureDispatch
> ie = EnsureDispatch('InternetExplorer.Application')
> ie.Navigate('http://www.facebook.com')
> print ie.Document.documentElement.innerHTML


When I execute the script, I have this error :

> >>>
> Traceback (most recent call last):
>   File "C:\Documents and Settings\adlemair\Bureau\exos\connectFacebook.py",
> line 18, in <module>
>     from win32com.client.gencache import EnsureDispatch
>   File "C:\Python26\lib\site-packages\win32com\__init__.py", line 5, in
> <module>
>     import win32api, sys, os
> ImportError: DLL load failed: Le module spécifié est introuvable.


Do you know why ? Do you arrive to execute this script on your side ?


Thank you so much for your advise

Best regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090724/ff53effb/attachment.htm>


More information about the python-win32 mailing list