回答編集履歴
3
問題個所指摘追加
answer
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
つまり、html_soup の中に input がないか name が protection という項目がなかったということ。
|
7
7
|
|
8
8
|
print(html_soup) を実行して、findしようとしてる項目があるか確認してみてはいかがですか?
|
9
|
+
テキストには postform3 と書いてあるようにみえるけど・・・
|
9
10
|
|
10
11
|
```
|
11
12
|
>>> import requests
|
2
実行例表示
answer
CHANGED
@@ -8,6 +8,49 @@
|
|
8
8
|
print(html_soup) を実行して、findしようとしてる項目があるか確認してみてはいかがですか?
|
9
9
|
|
10
10
|
```
|
11
|
+
>>> import requests
|
12
|
+
>>> from bs4 import BeautifulSoup
|
13
|
+
>>> url = 'http://www.webscrapingfordatascience.com/postform2/'
|
14
|
+
>>> r = requests.get(url)
|
15
|
+
>>> html_soup = BeautifulSoup(r.text, 'html.parser')
|
16
|
+
>>> html_soup
|
17
|
+
<html>
|
18
|
+
<body>
|
19
|
+
<form method="POST">
|
20
|
+
<table border="1">
|
21
|
+
<tr style="background-color: #24afe2;"><th>Name</th><th>Value</th></tr>
|
22
|
+
<tr><td>Your name</td>
|
23
|
+
<td><input name="name" type="text"/></td></tr>
|
24
|
+
<tr><td>Your gender</td>
|
25
|
+
<td><input name="gender" type="radio" value="M"/>Male<br/>
|
26
|
+
<input name="gender" type="radio" value="F"/>Female<br/>
|
27
|
+
<input name="gender" type="radio" value="N"/>Other / prefer not to say</td></tr>
|
28
|
+
<tr><td>Food you like</td>
|
29
|
+
<td><input name="pizza" type="checkbox" value="like"/>Pizza!<br/>
|
30
|
+
<input name="fries" type="checkbox" value="like"/>Fries please<br/>
|
31
|
+
<input name="salad" type="checkbox" value="like"/>Salad for me</td></tr>
|
32
|
+
<tr><td>Your hair color</td>
|
33
|
+
<td>
|
34
|
+
<select name="haircolor">
|
35
|
+
<option value="black">Black hair</option>
|
36
|
+
<option value="brown">Brown hair</option>
|
37
|
+
<option value="blonde">Blonde hair</option>
|
38
|
+
<option value="other">Other</option>
|
39
|
+
</select>
|
40
|
+
</td></tr>
|
41
|
+
<tr><td>Any more comments?</td>
|
42
|
+
<td>
|
43
|
+
<textarea name="comments"></textarea>
|
44
|
+
</td></tr>
|
45
|
+
<tr><td>Ready?</td>
|
46
|
+
<td>
|
47
|
+
<input type="submit" value="Submit my information"/>
|
48
|
+
</td></tr>
|
49
|
+
</table>
|
50
|
+
</form>
|
51
|
+
</body>
|
52
|
+
</html>
|
53
|
+
|
11
54
|
>>> x = html_soup.find('input', attrs={'name':'protocol'})
|
12
55
|
>>> print(x)
|
13
56
|
None
|
1
実行例追加
answer
CHANGED
@@ -5,4 +5,13 @@
|
|
5
5
|
None になっているのは html_soup.find('input', attrs={'name': 'protection'}) の部分。
|
6
6
|
つまり、html_soup の中に input がないか name が protection という項目がなかったということ。
|
7
7
|
|
8
|
-
print(html_soup) を実行して、findしようとしてる項目があるか確認してみてはいかがですか?
|
8
|
+
print(html_soup) を実行して、findしようとしてる項目があるか確認してみてはいかがですか?
|
9
|
+
|
10
|
+
```
|
11
|
+
>>> x = html_soup.find('input', attrs={'name':'protocol'})
|
12
|
+
>>> print(x)
|
13
|
+
None
|
14
|
+
>>> x = html_soup.find('input')
|
15
|
+
>>> print(x)
|
16
|
+
<input name="name" type="text"/>
|
17
|
+
```
|