回答編集履歴
3
問題個所指摘追加
test
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
print(html_soup) を実行して、findしようとしてる項目があるか確認してみてはいかがですか?
|
16
|
+
|
17
|
+
テキストには postform3 と書いてあるようにみえるけど・・・
|
16
18
|
|
17
19
|
|
18
20
|
|
2
実行例表示
test
CHANGED
@@ -18,6 +18,92 @@
|
|
18
18
|
|
19
19
|
```
|
20
20
|
|
21
|
+
>>> import requests
|
22
|
+
|
23
|
+
>>> from bs4 import BeautifulSoup
|
24
|
+
|
25
|
+
>>> url = 'http://www.webscrapingfordatascience.com/postform2/'
|
26
|
+
|
27
|
+
>>> r = requests.get(url)
|
28
|
+
|
29
|
+
>>> html_soup = BeautifulSoup(r.text, 'html.parser')
|
30
|
+
|
31
|
+
>>> html_soup
|
32
|
+
|
33
|
+
<html>
|
34
|
+
|
35
|
+
<body>
|
36
|
+
|
37
|
+
<form method="POST">
|
38
|
+
|
39
|
+
<table border="1">
|
40
|
+
|
41
|
+
<tr style="background-color: #24afe2;"><th>Name</th><th>Value</th></tr>
|
42
|
+
|
43
|
+
<tr><td>Your name</td>
|
44
|
+
|
45
|
+
<td><input name="name" type="text"/></td></tr>
|
46
|
+
|
47
|
+
<tr><td>Your gender</td>
|
48
|
+
|
49
|
+
<td><input name="gender" type="radio" value="M"/>Male<br/>
|
50
|
+
|
51
|
+
<input name="gender" type="radio" value="F"/>Female<br/>
|
52
|
+
|
53
|
+
<input name="gender" type="radio" value="N"/>Other / prefer not to say</td></tr>
|
54
|
+
|
55
|
+
<tr><td>Food you like</td>
|
56
|
+
|
57
|
+
<td><input name="pizza" type="checkbox" value="like"/>Pizza!<br/>
|
58
|
+
|
59
|
+
<input name="fries" type="checkbox" value="like"/>Fries please<br/>
|
60
|
+
|
61
|
+
<input name="salad" type="checkbox" value="like"/>Salad for me</td></tr>
|
62
|
+
|
63
|
+
<tr><td>Your hair color</td>
|
64
|
+
|
65
|
+
<td>
|
66
|
+
|
67
|
+
<select name="haircolor">
|
68
|
+
|
69
|
+
<option value="black">Black hair</option>
|
70
|
+
|
71
|
+
<option value="brown">Brown hair</option>
|
72
|
+
|
73
|
+
<option value="blonde">Blonde hair</option>
|
74
|
+
|
75
|
+
<option value="other">Other</option>
|
76
|
+
|
77
|
+
</select>
|
78
|
+
|
79
|
+
</td></tr>
|
80
|
+
|
81
|
+
<tr><td>Any more comments?</td>
|
82
|
+
|
83
|
+
<td>
|
84
|
+
|
85
|
+
<textarea name="comments"></textarea>
|
86
|
+
|
87
|
+
</td></tr>
|
88
|
+
|
89
|
+
<tr><td>Ready?</td>
|
90
|
+
|
91
|
+
<td>
|
92
|
+
|
93
|
+
<input type="submit" value="Submit my information"/>
|
94
|
+
|
95
|
+
</td></tr>
|
96
|
+
|
97
|
+
</table>
|
98
|
+
|
99
|
+
</form>
|
100
|
+
|
101
|
+
</body>
|
102
|
+
|
103
|
+
</html>
|
104
|
+
|
105
|
+
|
106
|
+
|
21
107
|
>>> x = html_soup.find('input', attrs={'name':'protocol'})
|
22
108
|
|
23
109
|
>>> print(x)
|
1
実行例追加
test
CHANGED
@@ -13,3 +13,21 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
print(html_soup) を実行して、findしようとしてる項目があるか確認してみてはいかがですか?
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
>>> x = html_soup.find('input', attrs={'name':'protocol'})
|
22
|
+
|
23
|
+
>>> print(x)
|
24
|
+
|
25
|
+
None
|
26
|
+
|
27
|
+
>>> x = html_soup.find('input')
|
28
|
+
|
29
|
+
>>> print(x)
|
30
|
+
|
31
|
+
<input name="name" type="text"/>
|
32
|
+
|
33
|
+
```
|