pythonで自作のログインフォーム(↓)にログインしたいのですが、
pythonAのやり方だとログインできるのですが、pythonBのやり方だとログイン前の画面が表示されてしまうのですが、なんででしょうか?
HTML
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <title>ログイン画面</title> 6</head> 7<body> 8<h1>ログイン</h1> 9<form action="login.php" method="POST"> 10<p>メールアドレス:<input type="text" name="email"> 11<p>パスワード:<input type="password" name="password"> 12<p><input type="submit" value="ログイン"></p> 13<p><a href="signup.php">新規登録</a></p> 14</form> 15</body> 16</html> 17
pythonA
1import requests 2 3email = "a@a.com" 4password = "1234" 5 6session = requests.session() 7 8login_info = { 9 "email":email, 10 "password":password, 11} 12 13url_login = "http://localhost/practice/13/login.php" 14res = session.post(url_login, data=login_info) 15 16print(res.text) 17 18
pythonB
1import urllib.request 2import urllib.parse 3 4params ={ 5 "email": "a@a.com", 6 "password":"1234", 7} 8 9data = urllib.parse.urlencode(params).encode("utf-8") 10with urllib.request.urlopen("http://localhost/practice/13/login.php", data=data) as res: 11 html = res.read().decode("utf-8") 12 print(html) 13
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/13 15:40