質問編集履歴
2
ソース追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,11 +60,11 @@
|
|
60
60
|
|
61
61
|
#メアドと、パスワードを入力
|
62
62
|
|
63
|
-
driver.find_element_by_name('username').send_keys('
|
63
|
+
driver.find_element_by_name('username').send_keys('****')
|
64
|
-
|
64
|
+
|
65
|
-
time.sleep(1)
|
65
|
+
time.sleep(1)
|
66
|
-
|
66
|
+
|
67
|
-
driver.find_element_by_name('password').send_keys('
|
67
|
+
driver.find_element_by_name('password').send_keys('*****')
|
68
68
|
|
69
69
|
time.sleep(1)
|
70
70
|
|
1
ソースコード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,3 +17,403 @@
|
|
17
17
|
teratermからSSHで接続して実行したら動かないです。
|
18
18
|
|
19
19
|
SSHでつないでseleniumを使ったプログラムを動かすにはどうしたらよいでしょうか?
|
20
|
+
|
21
|
+
```ここに言語を入力
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
from selenium import webdriver
|
26
|
+
|
27
|
+
from selenium.common.exceptions import WebDriverException
|
28
|
+
|
29
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
30
|
+
|
31
|
+
from selenium.webdriver.common.keys import Keys
|
32
|
+
|
33
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
34
|
+
|
35
|
+
from selenium.common.exceptions import TimeoutException
|
36
|
+
|
37
|
+
from selenium.webdriver.chrome.options import Options
|
38
|
+
|
39
|
+
import time
|
40
|
+
|
41
|
+
import random
|
42
|
+
|
43
|
+
import platform
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def login():
|
48
|
+
|
49
|
+
driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
|
50
|
+
|
51
|
+
f = open('insta.txt','a')
|
52
|
+
|
53
|
+
f.write("instagramにアクセスしました\n")
|
54
|
+
|
55
|
+
f.close()
|
56
|
+
|
57
|
+
time.sleep(1)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
#メアドと、パスワードを入力
|
62
|
+
|
63
|
+
driver.find_element_by_name('username').send_keys('minamino.kaito')
|
64
|
+
|
65
|
+
time.sleep(1)
|
66
|
+
|
67
|
+
driver.find_element_by_name('password').send_keys('15246810')
|
68
|
+
|
69
|
+
time.sleep(1)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
#ログインボタンを押す
|
74
|
+
|
75
|
+
driver.find_element_by_class_name('L3NKy ').click()
|
76
|
+
|
77
|
+
time.sleep(random.randint(2, 5))
|
78
|
+
|
79
|
+
f = open('insta.txt','a')
|
80
|
+
|
81
|
+
f.write("ログイン完了\n")
|
82
|
+
|
83
|
+
f.close()
|
84
|
+
|
85
|
+
time.sleep(1)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def tagsearch(tag):
|
90
|
+
|
91
|
+
instaurl = 'https://www.instagram.com/explore/tags/'
|
92
|
+
|
93
|
+
driver.get(instaurl + tag)
|
94
|
+
|
95
|
+
time.sleep(random.randint(2, 10))
|
96
|
+
|
97
|
+
f = open('insta.txt','a')
|
98
|
+
|
99
|
+
f.write("tag検索の実施\n")
|
100
|
+
|
101
|
+
f.close()
|
102
|
+
|
103
|
+
time.sleep(1)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
def clicknice():
|
108
|
+
|
109
|
+
target = driver.find_elements_by_class_name('_9AhH0')[10]
|
110
|
+
|
111
|
+
actions = ActionChains(driver)
|
112
|
+
|
113
|
+
actions.move_to_element(target)
|
114
|
+
|
115
|
+
actions.perform()
|
116
|
+
|
117
|
+
time.sleep(1)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
try:
|
122
|
+
|
123
|
+
driver.find_elements_by_class_name('_9AhH0')[9].click()
|
124
|
+
|
125
|
+
time.sleep(random.randint(2, 10))
|
126
|
+
|
127
|
+
f = open('insta.txt','a')
|
128
|
+
|
129
|
+
f.write("投稿をクリック\n")
|
130
|
+
|
131
|
+
f.close()
|
132
|
+
|
133
|
+
time.sleep(1)
|
134
|
+
|
135
|
+
driver.find_element_by_class_name('fr66n').click()
|
136
|
+
|
137
|
+
f = open('insta.txt','a')
|
138
|
+
|
139
|
+
f.write("投稿をいいね\n")
|
140
|
+
|
141
|
+
f.close()
|
142
|
+
|
143
|
+
time.sleep(1)
|
144
|
+
|
145
|
+
#if random.randint(1,2)==1:
|
146
|
+
|
147
|
+
follow()
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
except WebDriverException:
|
154
|
+
|
155
|
+
f = open('insta.txt','a')
|
156
|
+
|
157
|
+
f.write("エラーが発生しました\n")
|
158
|
+
|
159
|
+
f.close()
|
160
|
+
|
161
|
+
return
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
for i in range(1,80):
|
166
|
+
|
167
|
+
try:
|
168
|
+
|
169
|
+
driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click()
|
170
|
+
|
171
|
+
f = open('insta.txt','a')
|
172
|
+
|
173
|
+
f.write("次の投稿へ移動しました\n")
|
174
|
+
|
175
|
+
f.close()
|
176
|
+
|
177
|
+
time.sleep(random.randint(random.randint(2, 5), random.randint(10, 15)))
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
except WebDriverException:
|
182
|
+
|
183
|
+
f = open('insta.txt','a')
|
184
|
+
|
185
|
+
f.write("2つ目の位置でエラーが発生しました\n")
|
186
|
+
|
187
|
+
f.close()
|
188
|
+
|
189
|
+
time.sleep(5)
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
try:
|
194
|
+
|
195
|
+
driver.find_element_by_class_name('fr66n').click()
|
196
|
+
|
197
|
+
f = open('insta.txt','a')
|
198
|
+
|
199
|
+
f.write("投稿をいいねしました\n")
|
200
|
+
|
201
|
+
f.close()
|
202
|
+
|
203
|
+
time.sleep(random.randint(1,3))
|
204
|
+
|
205
|
+
#if random.randint(1,2)==1:
|
206
|
+
|
207
|
+
follow()
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
except WebDriverException:
|
212
|
+
|
213
|
+
f = open('insta.txt','a')
|
214
|
+
|
215
|
+
f.write("3つ目の位置でエラーが発生しました\n")
|
216
|
+
|
217
|
+
f.close()
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
def follow():
|
222
|
+
|
223
|
+
#アカウントの要素を取得
|
224
|
+
|
225
|
+
target = driver.find_element_by_css_selector('.e1e1d .Jv7Aj')
|
226
|
+
|
227
|
+
targetelem = target.find_element_by_tag_name("a")
|
228
|
+
|
229
|
+
url = targetelem.get_attribute("href")
|
230
|
+
|
231
|
+
print(url)
|
232
|
+
|
233
|
+
#クリック前のハンドルリスト
|
234
|
+
|
235
|
+
handles_befor = driver.window_handles
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
#ctrlキーで新しいタブを開こうとした残骸ココカラ
|
240
|
+
|
241
|
+
#actions = ActionChains(driver)
|
242
|
+
|
243
|
+
#actions.reset_actions()
|
244
|
+
|
245
|
+
#if platform.system() == 'Darwin':
|
246
|
+
|
247
|
+
#Macなのでコマンドキー
|
248
|
+
|
249
|
+
# actions.key_down(Keys.COMMAND)
|
250
|
+
|
251
|
+
#else:
|
252
|
+
|
253
|
+
#Mac以外なのでコントロールキー
|
254
|
+
|
255
|
+
#actions.key_down(Keys.CONTROL)
|
256
|
+
|
257
|
+
#target.click()
|
258
|
+
|
259
|
+
#actions.click(target)
|
260
|
+
|
261
|
+
#actions.perform
|
262
|
+
|
263
|
+
#ctrlキーで新しいタブを開こうとした残骸ココマデ
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
#新しいタブを開く
|
268
|
+
|
269
|
+
driver.execute_script("window.open()")
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
print("プロフィールを開く")
|
274
|
+
|
275
|
+
time.sleep(random.randint(3, 6))
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
handles_after = driver.window_handles
|
280
|
+
|
281
|
+
handle_new = list(set(handles_after) - set(handles_befor))
|
282
|
+
|
283
|
+
driver.switch_to.window(handle_new[0])
|
284
|
+
|
285
|
+
print("window切り替え")
|
286
|
+
|
287
|
+
#プロフィールを開く
|
288
|
+
|
289
|
+
driver.get(url)
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
target = driver.find_elements_by_class_name('vBF20')
|
294
|
+
|
295
|
+
targetelem = None
|
296
|
+
|
297
|
+
#フォローボタンをサーチ
|
298
|
+
|
299
|
+
for baf in target:
|
300
|
+
|
301
|
+
if (baf.text == "フォローする" ):
|
302
|
+
|
303
|
+
print("フォローするになっているか確認完了")
|
304
|
+
|
305
|
+
targetelem = baf
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
#actions = ActionChains(driver)
|
310
|
+
|
311
|
+
#カーソル移動
|
312
|
+
|
313
|
+
#actions.click(targetelem)
|
314
|
+
|
315
|
+
#実行
|
316
|
+
|
317
|
+
#actions.perform()
|
318
|
+
|
319
|
+
f = open('insta.txt','a')
|
320
|
+
|
321
|
+
f.write("フォローボタンにカーソルを合わせました\n")
|
322
|
+
|
323
|
+
f.close()
|
324
|
+
|
325
|
+
time.sleep(1)
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
try:
|
330
|
+
|
331
|
+
if(targetelem != None):
|
332
|
+
|
333
|
+
targetelem.click()
|
334
|
+
|
335
|
+
time.sleep(random.randint(2, 10))
|
336
|
+
|
337
|
+
f = open('insta.txt','a')
|
338
|
+
|
339
|
+
f.write("フォローしました\n")
|
340
|
+
|
341
|
+
f.close()
|
342
|
+
|
343
|
+
time.sleep(1)
|
344
|
+
|
345
|
+
time.sleep(random.randint(2, 10))
|
346
|
+
|
347
|
+
driver.close()
|
348
|
+
|
349
|
+
driver.switch_to.window(driver.window_handles[0])
|
350
|
+
|
351
|
+
except WebDriverException:
|
352
|
+
|
353
|
+
f = open('insta.txt','a')
|
354
|
+
|
355
|
+
f.write("エラーが発生しました\n")
|
356
|
+
|
357
|
+
f.close()
|
358
|
+
|
359
|
+
return
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
if __name__ == '__main__':
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
taglist = ['f4f', 'l4l','like4like', 'instagood','フォロー返します', 'いいね返し','フォロバ100','筋肉','いいねした人全員フォローする']
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
#while True:
|
378
|
+
|
379
|
+
driver = webdriver.Chrome('chromedriver')
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
#options = Options()
|
384
|
+
|
385
|
+
#options.binary_location = '/usr/bin/google-chrome'
|
386
|
+
|
387
|
+
#options.add_argument('--headless')
|
388
|
+
|
389
|
+
#driver = webdriver.Chrome(options=options)
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
time.sleep(1)
|
394
|
+
|
395
|
+
login()
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
tagsearch(random.choice(taglist))
|
400
|
+
|
401
|
+
clicknice()
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
driver.close()
|
406
|
+
|
407
|
+
#待機秒数の設定
|
408
|
+
|
409
|
+
#abc = random.randint(random.randint(20, 100), random.randint(120, 1800))
|
410
|
+
|
411
|
+
#f = open('insta.txt','a')
|
412
|
+
|
413
|
+
#f.write(str(abc)+"秒待機します\n")
|
414
|
+
|
415
|
+
#f.close()
|
416
|
+
|
417
|
+
#time.sleep(abc)
|
418
|
+
|
419
|
+
```
|