質問編集履歴

1

コードの追加

2018/04/01 13:18

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -5,3 +5,69 @@
5
5
 
6
6
 
7
7
  このような感じです。色々調べたのですがnot writableのエラーはfile処理の問題が多く、自分では解決できませんでしたので、ご教授お願い致します。
8
+
9
+
10
+
11
+ ```python
12
+
13
+ import requests
14
+
15
+ res = requests.get('https://tonari-it.com')
16
+
17
+ res.raise_for_status()
18
+
19
+ print(res.text)
20
+
21
+ ```
22
+
23
+
24
+
25
+ ```python
26
+
27
+ from selenium import webdriver
28
+
29
+ from bs4 import BeautifulSoup
30
+
31
+ import sys, io
32
+
33
+
34
+
35
+ # UTF8にエンコード
36
+
37
+ sys.stdout = io.TextIOWrapper(sys.stdout, encoding='utf-8')
38
+
39
+
40
+
41
+ # ブラウザを操作するオブジェクトの生成
42
+
43
+ driver = webdriver.Chrome()
44
+
45
+ # 指定したURLへの移動
46
+
47
+ driver.get("https://facebook.com")
48
+
49
+ # ページのHTMLを取得
50
+
51
+ html = driver.page_source
52
+
53
+ # ブラウザの終了
54
+
55
+ driver.close()
56
+
57
+
58
+
59
+ # 取得したHTMLからBeautifulSoupオブフェクトを生成
60
+
61
+ # scriptやstyle及びその他タグの除去
62
+
63
+ soup = BeautifulSoup(html, "lxml")
64
+
65
+ for s in soup(['script', 'style']):
66
+
67
+ s.decompose()
68
+
69
+ text = ' '.join(soup.stripped_strings)
70
+
71
+ print(text)
72
+
73
+ ```