質問編集履歴
4
コードを実行するとエラーが出てきました。修正したのでこのコードでしたらきちんと実行されます。
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
```
|
17
17
|
|
18
18
|
### 該当のソースコード
|
19
|
-
|
19
|
+
mport requests
|
20
20
|
from bs4 import BeautifulSoup
|
21
21
|
import difflib as diff
|
22
22
|
import os
|
@@ -27,7 +27,7 @@
|
|
27
27
|
def readlines_newfile():
|
28
28
|
fd_newfile = open('newfile.txt','r')
|
29
29
|
data_newfile = fd_newfile.readlines()
|
30
|
-
newfile_list
|
30
|
+
newfile_list = data_newfile
|
31
31
|
fd_newfile.close()
|
32
32
|
print(data_newfile)
|
33
33
|
|
@@ -68,6 +68,7 @@
|
|
68
68
|
print(len(benzai_list))
|
69
69
|
print(len(newfile_list))
|
70
70
|
|
71
|
+
|
71
72
|
```ここに言語名を入力
|
72
73
|
Pyrhon3
|
73
74
|
```
|
3
コードをそのまま加筆なしで上げました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,27 +18,36 @@
|
|
18
18
|
### 該当のソースコード
|
19
19
|
import requests
|
20
20
|
from bs4 import BeautifulSoup
|
21
|
+
import difflib as diff
|
22
|
+
import os
|
21
23
|
|
22
24
|
newfile_list = 'a'
|
23
25
|
benzai_list = 'a'
|
24
26
|
|
25
|
-
#ファイルに書いてある内容をリスト型に格納する関数
|
26
27
|
def readlines_newfile():
|
27
28
|
fd_newfile = open('newfile.txt','r')
|
28
29
|
data_newfile = fd_newfile.readlines()
|
29
|
-
newfile_list
|
30
|
+
newfile_list = data_newfile
|
30
31
|
fd_newfile.close()
|
32
|
+
print(data_newfile)
|
31
33
|
|
32
34
|
def readlines_benzai():
|
33
35
|
fd_benzai = open('benzai.txt', 'r')
|
34
36
|
data_benzai = fd_benzai.readlines()
|
35
37
|
benzai_list = data_benzai
|
36
38
|
fd_benzai.close()
|
39
|
+
print(data_benzai)
|
37
40
|
|
38
|
-
|
41
|
+
r1 = requests.get("https://venzaiten.com/category/%e6%97%a5%e7%b5%8c225%e5%85%88%e7%89%a9/livetrade")
|
39
|
-
r = requests.get(link)
|
40
42
|
|
43
|
+
soup1 = BeautifulSoup(r1.text, "html.parser")
|
44
|
+
soup2 = soup1.find("li","post_type1 post_num1 clearfix" )
|
45
|
+
soup3 = soup2.find("h4", "title")
|
46
|
+
soup4 = soup3.find("a")
|
47
|
+
link = soup4.get("href")
|
48
|
+
|
49
|
+
r2 = requests.get(link)
|
41
|
-
soupFinal = BeautifulSoup(
|
50
|
+
soupFinal = BeautifulSoup(r2.text, "html.parser")
|
42
51
|
soupRealTradeCollum = soupFinal.find("div", "post_content clearfix").text
|
43
52
|
|
44
53
|
InspectionFile = open("newfile.txt", "w+")
|
@@ -46,13 +55,19 @@
|
|
46
55
|
|
47
56
|
InspectionFile.close()
|
48
57
|
|
49
|
-
|
58
|
+
Entry = open("entry.txt", "w+")
|
59
|
+
|
50
60
|
readlines_newfile()
|
51
61
|
readlines_benzai()
|
52
62
|
|
63
|
+
print(benzai_list)
|
53
|
-
|
64
|
+
print(newfile_list)
|
65
|
+
|
54
66
|
print(benzai_list == newfile_list)
|
55
67
|
|
68
|
+
print(len(benzai_list))
|
69
|
+
print(len(newfile_list))
|
70
|
+
|
56
71
|
```ここに言語名を入力
|
57
72
|
Pyrhon3
|
58
73
|
```
|
2
質問とは関係ないコードを省略しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,11 +26,13 @@
|
|
26
26
|
def readlines_newfile():
|
27
27
|
fd_newfile = open('newfile.txt','r')
|
28
28
|
data_newfile = fd_newfile.readlines()
|
29
|
+
newfile_list = data_newfile
|
29
30
|
fd_newfile.close()
|
30
31
|
|
31
32
|
def readlines_benzai():
|
32
33
|
fd_benzai = open('benzai.txt', 'r')
|
33
34
|
data_benzai = fd_benzai.readlines()
|
35
|
+
benzai_list = data_benzai
|
34
36
|
fd_benzai.close()
|
35
37
|
|
36
38
|
#requestsとbs4を用いてサイト記事から記事のテキストをファイル(newfile.txt)に書き込む(サイトURLは省略しています。)
|
1
質問とは無関係なコードがありましたので省略しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,17 +34,9 @@
|
|
34
34
|
fd_benzai.close()
|
35
35
|
|
36
36
|
#requestsとbs4を用いてサイト記事から記事のテキストをファイル(newfile.txt)に書き込む(サイトURLは省略しています。)
|
37
|
-
|
37
|
+
r = requests.get(link)
|
38
38
|
|
39
|
-
soup1 = BeautifulSoup(r1.text, "html.parser")
|
40
|
-
soup2 = soup1.find("li","post_type1 post_num1 clearfix" )
|
41
|
-
soup3 = soup2.find("h4", "title")
|
42
|
-
soup4 = soup3.find("a")
|
43
|
-
link = soup4.get("href")
|
44
|
-
|
45
|
-
r2 = requests.get(link)
|
46
|
-
|
47
|
-
soupFinal = BeautifulSoup(
|
39
|
+
soupFinal = BeautifulSoup(r.text, "html.parser")
|
48
40
|
soupRealTradeCollum = soupFinal.find("div", "post_content clearfix").text
|
49
41
|
|
50
42
|
InspectionFile = open("newfile.txt", "w+")
|