質問編集履歴

4

codeの修正

2019/08/16 16:48

投稿

atk_721
atk_721

スコア62

test CHANGED
File without changes
test CHANGED
@@ -36,6 +36,10 @@
36
36
 
37
37
  import requests
38
38
 
39
+ from bs4 import BeautifulSoup
40
+
41
+
42
+
39
43
  cakes = []
40
44
 
41
45
  urls = create_url(http)
@@ -48,13 +52,11 @@
48
52
 
49
53
  contents = bs.find_all('div',class_='Menu')
50
54
 
51
-
52
-
53
55
  for content in contents:
54
56
 
55
- title = content.find('div',class_='cake').find('a')
57
+ cake_name = content.find('div',class_='cake').find('a')
56
58
 
57
- titles.append(title.text)
59
+ cakes.append(cake_name.text)
58
60
 
59
61
 
60
62
 

3

codeの修正

2019/08/16 16:48

投稿

atk_721
atk_721

スコア62

test CHANGED
File without changes
test CHANGED
@@ -2,19 +2,21 @@
2
2
 
3
3
  ```ここに言語を入力
4
4
 
5
- titles = []
5
+ cakes = []
6
-
7
- messages = []
8
-
9
- companys = []
10
-
11
- links = []
12
6
 
13
7
  ```
14
8
 
15
- この個別のリストの中身を重複しないようにしたい。
9
+ このリストの中身を重複しないようにしたい。
16
10
 
17
11
  どのような書き方があるのか知りたいです。
12
+
13
+
14
+
15
+ 前回のコードは、規約違反でしたので削除しました。
16
+
17
+ 指摘ありがとうございました。
18
+
19
+
18
20
 
19
21
 
20
22
 
@@ -30,100 +32,30 @@
30
32
 
31
33
  ```ここに言語名を入力
32
34
 
33
- def create_url(words,live,pages):
34
35
 
35
- urls = []
36
36
 
37
- pages = int(pages)
37
+ import requests
38
38
 
39
- _url = 'https://jp.indeed.com/jobs?q={}%E3%80%80&l={}&start='.format(words,live)
39
+ cakes = []
40
40
 
41
- for i in range(10,(pages*10)+10,10):
41
+ urls = create_url(http)
42
42
 
43
- url = _url+'{}'.format(i)
43
+ for url in urls:
44
44
 
45
- urls.append(url)
45
+ r = requests.get(url)
46
46
 
47
+ bs =BeautifulSoup(r.text,'lxml')
48
+
49
+ contents = bs.find_all('div',class_='Menu')
50
+
51
+
52
+
47
- return urls
53
+ for content in contents:
54
+
55
+ title = content.find('div',class_='cake').find('a')
56
+
57
+ titles.append(title.text)
48
58
 
49
59
 
50
60
 
51
- def job_search(words,live,pages):
52
-
53
-
54
-
55
- import requests
56
-
57
- from bs4 import BeautifulSoup
58
-
59
-
60
-
61
- titles = []
62
-
63
- messages = []
64
-
65
- companys = []
66
-
67
- links = []
68
-
69
- scheme='https://jp.indeed.com/'
70
-
71
-
72
-
73
- urls = create_url(words,live,pages)
74
-
75
- for url in urls:
76
-
77
- r = requests.get(url)
78
-
79
- bs =BeautifulSoup(r.text,'lxml')
80
-
81
- contents = bs.find_all('div',class_='jobsearch-SerpJobCard')
82
-
83
-
84
-
85
- for content in contents:
86
-
87
- title = content.find('div',class_='title').find('a')
88
-
89
- titles.append(title.text)
90
-
91
-
92
-
93
- message = content.find('div',class_='summary')
94
-
95
- messages.append(message.text)
96
-
97
-
98
-
99
- company = content.find('div',class_='sjcl').find('span',class_='company')
100
-
101
- companys.append(company.text)
102
-
103
-
104
-
105
- link = scheme+content.find('a').get('href')
106
-
107
- links.append(link)
108
-
109
-
110
-
111
- return titles,messages,companys,links
112
-
113
-
114
-
115
- def job_printer(word,live,pages):
116
-
117
- titles,messages,companys,links = job_search(word,live,pages)
118
-
119
- print('\n\n')
120
-
121
- print('{}社見つかりました。\n\n 検索ワード:{}\t所在市:{}\tページ数:{}'.format(len(companys),word,live,pages))
122
-
123
- for i in range(len(messages)):
124
-
125
- print(titles[i],'\n',messages[i],'\n',companys[i],'\n',links[i])
126
-
127
- print('\n\n')
128
-
129
61
  ```

2

codeの修正

2019/08/16 08:30

投稿

atk_721
atk_721

スコア62

test CHANGED
File without changes
test CHANGED
@@ -66,8 +66,6 @@
66
66
 
67
67
  links = []
68
68
 
69
- checkbox = []
70
-
71
69
  scheme='https://jp.indeed.com/'
72
70
 
73
71
 
@@ -82,25 +80,9 @@
82
80
 
83
81
  contents = bs.find_all('div',class_='jobsearch-SerpJobCard')
84
82
 
85
-
86
83
 
87
- _titles = ''
88
-
89
- _messages = ''
90
-
91
- _companys =''
92
-
93
- _links = ''
94
-
95
- _checkbox = []
96
-
97
-
98
84
 
99
85
  for content in contents:
100
-
101
- if content not in checkbox:
102
-
103
- _checkbox.append(content)
104
86
 
105
87
  title = content.find('div',class_='title').find('a')
106
88
 
@@ -124,30 +106,24 @@
124
106
 
125
107
  links.append(link)
126
108
 
109
+
127
110
 
128
-
129
- checkbox.append(_checkbox )
130
-
131
- titles.append(_titles)
132
-
133
- messages.append(_messages)
134
-
135
- companys.append(_companys)
111
+ return titles,messages,companys,links
136
-
137
- links.append(_links)
138
112
 
139
113
 
140
114
 
115
+ def job_printer(word,live,pages):
116
+
141
- return titles,messages,companys,links
117
+ titles,messages,companys,links = job_search(word,live,pages)
118
+
119
+ print('\n\n')
120
+
121
+ print('{}社見つかりました。\n\n 検索ワード:{}\t所在市:{}\tページ数:{}'.format(len(companys),word,live,pages))
122
+
123
+ for i in range(len(messages)):
124
+
125
+ print(titles[i],'\n',messages[i],'\n',companys[i],'\n',links[i])
126
+
127
+ print('\n\n')
142
128
 
143
129
  ```
144
-
145
-
146
-
147
- #試した解決方法
148
-
149
-
150
-
151
- checkboxというリストに全て入れて、重複していたら処理を行わないように自分なりに書いてみたのですがErrorは起きませんが、リストの要素は重複しています。
152
-
153
- 改善した方が良いところなどもあれば教えていただきたいです。

1

codeの修正

2019/08/16 07:32

投稿

atk_721
atk_721

スコア62

test CHANGED
@@ -1 +1 @@
1
- listに無いも要素のみを追加していきたい。
1
+ listに重複が無いように追加していきたい。
test CHANGED
File without changes