質問編集履歴

1

完成コード追記

2018/10/20 05:30

投稿

Yukiya025
Yukiya025

スコア86

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,61 @@
81
81
  個人情報について
82
82
 
83
83
  ```
84
+
85
+
86
+
87
+ # できました<3
88
+
89
+ [hayataka2049](https://teratail.com/users/hayataka2049)様のおかげで判定できるようになりました! ありがとうございます(≧▽≦) 以下の点も気をつけます^^/
90
+
91
+
92
+
93
+ > re.search()はマッチしなかったときNoneを返すので、結果を受け取る部分のコードに多少気を使ってあげてください
94
+
95
+
96
+
97
+ ```python
98
+
99
+ def get_html():
100
+
101
+
102
+
103
+ r = requests.get("https://www.oreilly.co.jp/index.shtml")
104
+
105
+ r.encoding = r.apparent_encoding
106
+
107
+ html_doc = r.text
108
+
109
+ soup = BeautifulSoup(html_doc)
110
+
111
+
112
+
113
+ html1 = open('Oreilly.html', 'w')
114
+
115
+ html1.write(soup.prettify())
116
+
117
+ html1 = soup.prettify()
118
+
119
+
120
+
121
+ text1 = open('Oreilly.text', 'w')
122
+
123
+ text1.write(soup.get_text())
124
+
125
+
126
+
127
+ priv_htm = re.search(r"privacy policy|プライバシーポリシー|個人情報", html1).start()
128
+
129
+ if priv_htm != -1:
130
+
131
+ print(priv_htm)
132
+
133
+ print("hrefを取得します")
134
+
135
+
136
+
137
+ else: print("ありませんでした")
138
+
139
+ get_html()
140
+
141
+ ```