0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

44日目 Bebutifulsoupでinputの値をとってくる

Posted at

Formの値がnameで一意に決まる場合の設定です。

こちらのサイトを参考にしました。
Python Beautiful Soup - Getting input value

test.html
<html>

<form action="process">
<input type="hidden" name="_AntiCsrfToken" value="5435434354353453545">

</form>
</html>
test.py
from bs4 import BeautifulSoup 
res = open("test.html", encoding="utf-8")
soup = BeautifulSoup(res, "html.parser")

#findでとってくる
token = soup.find('input', {'name':'_AntiCsrfToken'})['value']
print(token)

#selectでとってくる
csrf = soup.select_one('input[name=_AntiCsrfToken]')['value']
print(csrf)

実行結果

$ python test.py
5435434354353453545
5435434354353453545

ばっちり!
これでいけそうです!!!

あとは、

###1.Ruby on Railsを始めよう
12分
忘れたくないので復習!

###Python 1
15分
四則演算、変数、型変換、if文
この辺は大丈夫そう!

###Python 2
32分
リスト、辞書、for、while
お買い物システムを作るのでした。
ちょっと手間取った感じ。

次は関数とかクラスとかわかりたいなあ。

(所要時間 2時間くらい)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?