我想创建一个脚本,在使用我的组合登录后返回 wordpress 仪表板,如下所示:(屏幕截图)
所以我创建了这个脚本
import urllib, urllib2, os, sys, requests , re
site = 'http://example.com/blog/'
username = 'username'
password = 'password'
url = site + '/wp-login.php'
req = urllib2.Request(url)
headers = {
"User-Agent" : "Mozilla/5.0 (Windows; Windows NT 6.1; WOW64; rv:2.0b2) Gecko/20100720 Firefox/4.0b2",
"Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language" : "es-es,es;q=0.8,en-us;q=0.5,en;q=0.3",
"Accept-Charset" : "ISO-8859-1,utf-8;q=0.7,*;q=0.7"}
data = [
("log",username),
("pwd",password),
("testcookie",1),
("submit","Log In"),
("redirect_to",'http://example.com/blog/wp-admin/'),
("rememberme","forever")]
req = urllib2.Request(url, urllib.urlencode(dict(data)), dict(headers))
response = urllib2.urlopen(req)
the_page=response.read()
with open('result.html', 'w+') as file:
file.write(the_page)
response.close()
print 'done'
我收到的是登录页面,而不是我的 WordPress 仪表板:(屏幕截图)
我用错误的组合测试了脚本,它返回登录页面,并出现如下错误:(屏幕截图)
知道如何获取仪表板吗?非常感谢您的帮助
ps:正确登录的 dict(response.headers) 是:
{'x-powered-by': 'PHP/5.3.28', 'transfer-encoding': 'chunked', 'set-cookie': 'wordpress_test_cookie=
WP+Cookie+check; path=/blog/, wordpress_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013
15:27:13 GMT; path=/blog/wp-admin, wordpress_sec_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 1
1-Aug-2013 15:27:13 GMT; path=/blog/wp-admin, wordpress_38b05fc993d7b123a9db72281bf1c40e=+; expires=
Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/wp-content/plugins, wordpress_sec_38b05fc993d7b123a9db7228
1bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/wp-content/plugins, wordpress_logged_i
n_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/, wordpress_
logged_in_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/, wo
rdpress_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/, word
press_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/, wordpr
ess_sec_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/, word
press_sec_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/, wo
rdpressuser_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/,
wordpresspass_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blog/
, wordpressuser_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/blo
g/, wordpresspass_38b05fc993d7b123a9db72281bf1c40e=+; expires=Sun, 11-Aug-2013 15:27:13 GMT; path=/b
log/', 'expires': 'Wed, 11 Jan 1984 05:00:00 GMT', 'server': 'Apache', 'last-modified': 'Mon, 11 Aug
2014 15:27:13 GMT', 'connection': 'close', 'pragma': 'no-cache', 'cache-control': 'no-cache, must-r
evalidate, max-age=0', 'date': 'Mon, 11 Aug 2014 15:27:13 GMT', 'x-frame-options': 'SAMEORIGIN', 'co
ntent-type': 'text/html; charset=UTF-8'}