forked from ElvinKim/2018_1_ITA_python_class_C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
20180201_1.py
120 lines (60 loc) · 1.51 KB
/
20180201_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from bs4 import BeautifulSoup
html_code ="""
<html>
<head>
<title>
The Dormouse's story
</title>
</head>
<body>
<p class="title">
<b id="story">
The Dormouse's story
</b>
</p>
<p class="story">
Once upon a time there were three little sisters; and their names were
<a class="sister" href="http://example.com/elsie" id="link1">
Elsie
</a>
,
<a class="sister" href="http://example.com/lacie" id="link2">
Lacie
</a>
and
<a class="sister" href="http://example.com/tillie" id="link2">
Tillie
</a>
; and they lived at the bottom of a well.
</p>
<p class="story">
...
</p>
<table>
<tr class="tr_1">
<td class="element1"> one </td>
<td class="element2"> two </td>
<td class="element3"> three </td>
</tr>
<tr class="tr_2">
<td class="element1"> one </td>
<td class="element2"> two </td>
<td class="element3"> three </td>
</tr>
<tr class="tr_3">
<td class="element1"> one </td>
<td class="element2"> two </td>
<td class="element3"> three </td>
</tr>
</table>
</body>
</html>
"""
soup = BeautifulSoup(html_code, "html.parser")
print(soup.title)
print(soup.title.name)
print(soup.title.text)
print(soup.find_all("td"))
print(soup.find_all("td")[0].text)
print(soup.find_all("td", {"class": "element1"}))
print(soup.find("tr", {"class": "tr_1"}).find_all("td"))