teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

少し改変しました。

2020/07/28 12:15

投稿

onosan
onosan

スコア62

title CHANGED
File without changes
body CHANGED
@@ -5,8 +5,9 @@
5
5
 
6
6
  https://nintei.nurse.or.jp/certification/General/(X(1)S(efl0y555pect3x45oxjzfw3x))/General/GCPP01LS/GCPP01LS.aspx?AspxAutoDetectCookieSupport=1
7
7
 
8
- 以前に試した方法として、以下のようなものをテンプレートにしているのですが、エラーは起きないのですが、うまく取得できません。```python
8
+ 以前に試した方法として、以下のようなものをテンプレートにしているのですが、エラーは起きないのですが、うまく取得できません。
9
9
 
10
+ ```Python3
10
11
 
11
12
  #保存用
12
13
 
@@ -83,5 +84,4 @@
83
84
  dw_xlsx = [f for f in dw_list]
84
85
  for dw in dw_xlsx:
85
86
  shutil.move(r'C:\Users\akira\Documents\Python\会社')
86
-
87
87
  ```

5

少し改変しました。

2020/07/28 12:15

投稿

onosan
onosan

スコア62

title CHANGED
File without changes
body CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  soup = bs4.BeautifulSoup(driver.page_source, 'html5lib')
42
42
 
43
- base = 'https://web.shionogi.co.jp/mstr/microstrategy/asp/'
43
+ base = 'https://nintei.nurse.or.jp/certification/General/'
44
44
 
45
45
  soup_file1 = soup.find_all('a')
46
46
  href_list = []

4

余計な部分を省きました

2020/07/28 11:33

投稿

onosan
onosan

スコア62

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,7 @@
8
8
  以前に試した方法として、以下のようなものをテンプレートにしているのですが、エラーは起きないのですが、うまく取得できません。```python
9
9
 
10
10
 
11
- #保存用(SHIFTデータのダウンロード可能)
11
+ #保存用
12
12
 
13
13
  driver_path = r'C:\Anaconda3\chromedriver.exe'#自分のChoromedriverの場所
14
14
 

3

余計な部分を省きました

2020/07/28 11:26

投稿

onosan
onosan

スコア62

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  以前に試した方法として、以下のようなものをテンプレートにしているのですが、エラーは起きないのですが、うまく取得できません。```python
9
9
 
10
+
10
11
  #保存用(SHIFTデータのダウンロード可能)
11
12
 
12
13
  driver_path = r'C:\Anaconda3\chromedriver.exe'#自分のChoromedriverの場所
@@ -44,8 +45,8 @@
44
45
  soup_file1 = soup.find_all('a')
45
46
  href_list = []
46
47
 
47
- file_num = 1#len(os.listdir(r'C:\Users\{0}\Downloads'.format(myNo)))の初期値が1になるため
48
+ file_num = 1
48
- sum_file = 1#上と同じ理由
49
+ sum_file = 1
49
50
 
50
51
  cc = 0
51
52
  for s in soup_file1:

2

サンプルコードを追加しました

2020/07/28 11:24

投稿

onosan
onosan

スコア62

title CHANGED
File without changes
body CHANGED
@@ -56,8 +56,8 @@
56
56
  print(path)
57
57
  driver.get(path)
58
58
 
59
- WebDriverWait(driver, 300).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="3131"]')))
59
+ WebDriverWait(driver, 300).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="ctl00_plhContent_btnSearchMain"]')))
60
- driver.find_element_by_xpath('//*[@id="3131"]').click()
60
+ driver.find_element_by_xpath('//*[@id="ctl00_plhContent_btnSearchMain"]').click()
61
61
 
62
62
  while sum_file == file_num :
63
63
  sum_file = len(os.listdir(r'C:\Users\akira\Downloads'))

1

動かしたコードを書きました

2020/07/28 11:19

投稿

onosan
onosan

スコア62

title CHANGED
@@ -1,1 +1,1 @@
1
- メニューがたくさんあるウェブページから情報を一気に取得した
1
+ pythonのスクレイピングでデが取得できな
body CHANGED
@@ -3,4 +3,84 @@
3
3
 
4
4
  ウェブページは以下のものです。
5
5
 
6
- https://nintei.nurse.or.jp/certification/General/(X(1)S(efl0y555pect3x45oxjzfw3x))/General/GCPP01LS/GCPP01LS.aspx?AspxAutoDetectCookieSupport=1
6
+ https://nintei.nurse.or.jp/certification/General/(X(1)S(efl0y555pect3x45oxjzfw3x))/General/GCPP01LS/GCPP01LS.aspx?AspxAutoDetectCookieSupport=1
7
+
8
+ 以前に試した方法として、以下のようなものをテンプレートにしているのですが、エラーは起きないのですが、うまく取得できません。```python
9
+
10
+ #保存用(SHIFTデータのダウンロード可能)
11
+
12
+ driver_path = r'C:\Anaconda3\chromedriver.exe'#自分のChoromedriverの場所
13
+
14
+ #読み込みたいフォルダの場所
15
+ URL = 'https://nintei.nurse.or.jp/certification/General/(X(1)S(efl0y555pect3x45oxjzfw3x))/GCPP01LS/GCPP01LS.aspx'
16
+
17
+ #格納したいフォルダの場所
18
+ send_path = r'C:\Users\akira\Documents\Python\会社'
19
+
20
+
21
+
22
+ from selenium import webdriver
23
+ import time
24
+ import bs4
25
+ import re
26
+ import os
27
+ import time
28
+ import shutil
29
+ from selenium.webdriver.support.ui import WebDriverWait
30
+ from selenium.webdriver.support import expected_conditions as EC
31
+ from selenium.webdriver.common.by import By
32
+
33
+ start = time.time()
34
+
35
+
36
+ driver = webdriver.Chrome(driver_path)
37
+ driver.get(URL)
38
+ time.sleep(3)
39
+
40
+ soup = bs4.BeautifulSoup(driver.page_source, 'html5lib')
41
+
42
+ base = 'https://web.shionogi.co.jp/mstr/microstrategy/asp/'
43
+
44
+ soup_file1 = soup.find_all('a')
45
+ href_list = []
46
+
47
+ file_num = 1#len(os.listdir(r'C:\Users\{0}\Downloads'.format(myNo)))の初期値が1になるため
48
+ sum_file = 1#上と同じ理由
49
+
50
+ cc = 0
51
+ for s in soup_file1:
52
+ if s.string=='検索':
53
+ path = base+s.get('href')
54
+ href_list.append(path)
55
+
56
+ print(path)
57
+ driver.get(path)
58
+
59
+ WebDriverWait(driver, 300).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="3131"]')))
60
+ driver.find_element_by_xpath('//*[@id="3131"]').click()
61
+
62
+ while sum_file == file_num :
63
+ sum_file = len(os.listdir(r'C:\Users\akira\Downloads'))
64
+
65
+ else:
66
+ print("現在のダウンロードファイル数_{}枚".format(sum_file-1))
67
+ file_num += 1
68
+
69
+ cc += 1
70
+
71
+
72
+ #一時ファイルが邪魔をする場合があるので時間を少し開ける
73
+ time.sleep(60)
74
+
75
+
76
+ #ファイルの移動
77
+
78
+
79
+ dw_path = r'C:\Users\akira\Documents\Python\会社'
80
+ dw_list = os.listdir(dw_path)
81
+
82
+ dw_xlsx = [f for f in dw_list]
83
+ for dw in dw_xlsx:
84
+ shutil.move(r'C:\Users\akira\Documents\Python\会社')
85
+
86
+ ```