#coding:utf-8 #author:jwong import requests import urllib2 import re from bs4 import BeautifulSoup as bs def login(): s = requests.Session() login_url = ‘http://192.168.21.122/dvwa/login.php‘ content = s.get(login_url) pattern = re.compile("name=‘user_token‘ value=‘(.*?)‘") tokens = re.findall(pattern,content.text) token = tokens[0] data = { ‘username‘:‘admin‘, ‘password‘:‘password‘, ‘Login‘:‘Login‘, ‘user_token‘:token} headers = {‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0‘} res = s.post(login_url,data,headers=headers) re.compile(‘‘) spider(s) def spider(s): url_open = ‘http://192.168.21.122/dvwa/index.php‘ response = s.get(url_open) soup = bs(response.text) info = soup.find_all(‘a‘) print info exit() if __name__ == ‘__main__‘: login()
时间: 2024-10-03 00:15:49