【发布时间】:2014-10-02 20:38:58
【问题描述】:
我正在创建一个连接到 wordpress 并检测登录是否不正确的脚本,我不喜欢“如果包含”方法,所以我尝试使用它:
当您在 wordpress 站点中访问此 url 时:http://www.example.com/blog/wp-admin/profile.php 如果组合正确,则您可以正常访问该页面,如果不是重定向到此的 url:
http://www.example.com/blog/wp-login.php?redirect_to=http%3A%2F%2Fwww.example.com%2Fblog%2Fwp-admin%2Fprofile.php&reauth=1
所以我尝试了这段代码来验证 http 响应(300、301 ..),但它总是给出 200 响应..
import urllib, urllib2, os, sys, requests , re
from time import sleep
from threading import Thread
url='http://www.example.com/blog/wp-login.php'
headers = [
("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5")]
data = [
("log","user"),
("pwd","password"),
("testcookie",1),
("submit","Log In"),
("redirect_to","http://www.example.com/blog/wp-login.php"),
("rememberme","forever")]
#this is the first methode :
req = urllib2.Request(url, urllib.urlencode(dict(data)), dict(headers))
response = urllib2.urlopen(req)
the_page=response.read()
print the_page
#this is the seconde methode :
get3 = requests.get('http://www.example.com/blog/wp-admin/profile.php')
print get3.text
检测 url 变化的任何想法:http://www.example.com/blog/wp-admin/profile.php
到:
http://www.example.com/blog/wp-login.php?redirect_to=http%3A%2F%2Fwww.example.com%2Fblog%2Fwp-admin%2Fprofile.php&reauth=1
或者任何帮助我完成脚本的东西,这将非常有帮助,非常感谢。 :)
【问题讨论】: