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

質問編集履歴

1

2021/12/26 01:18

投稿

K_cek1005
K_cek1005

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,65 +1,2 @@
1
- seleniumを使って、ログインが必要なサイトのスクレイピングを試したのですが、
1
+ selenumでのスクレイピングにつ
2
- 拡張子がphpのサイトだとアクセスができません。
3
-
4
- お知恵を貸し頂ければ幸です。
2
+ お知恵を貸して下さ
5
-
6
-
7
-
8
- ### 発生している問題・エラーメッセージ
9
- 拡張子がphpのサイトのURLで実行すると、下記の結果が返ってきます
10
- ```
11
- <html><head><title>403 Forbidden</title></head>
12
- <body>
13
- <center><h1>403 Forbidden</h1></center>
14
-
15
-
16
- <!-- a padding to disable MSIE and Chrome friendly error page -->
17
- <!-- a padding to disable MSIE and Chrome friendly error page -->
18
- <!-- a padding to disable MSIE and Chrome friendly error page -->
19
- <!-- a padding to disable MSIE and Chrome friendly error page -->
20
- <!-- a padding to disable MSIE and Chrome friendly error page -->
21
- <!-- a padding to disable MSIE and Chrome friendly error page -->
22
- </body></html>
23
- ```
24
-
25
- ### 該当のソースコード
26
- ※アクセス先のURLは伏せています
27
-
28
- ```python
29
- #ライブラリをインポート
30
- from selenium import webdriver
31
- from selenium.webdriver.chrome.options import Options
32
- from selenium.webdriver.common.action_chains import ActionChains
33
- from selenium.webdriver.support.ui import Select
34
- import time
35
-
36
- # 処理開始
37
- # ブラウザをheadlessモード実行
38
- options = webdriver.ChromeOptions()
39
- options.add_argument('--headless')
40
- options.add_argument('--no-sandbox')
41
- options.add_argument('--disable-dev-shm-usage')
42
- options.add_argument('--ignore-certificate-errors')
43
- options.add_argument('--ignore-ssl-errors')
44
- driver = webdriver.Chrome('chromedriver',options=options)
45
- driver.implicitly_wait(10)
46
-
47
- # サイトにアクセス
48
- driver.get("〜〜〜.php")
49
- time.sleep(3)
50
-
51
- # ソースを表示してみる
52
- print(driver.page_source) # results
53
- ```
54
-
55
- ### 試したこと
56
-
57
- テストでGoogleのトップページ(https://www.google.com)や
58
- Yahooのログインページ(https://login.yahoo.co.jp/config/login)のURLを指定。
59
- いずれもアクセスでき、ソースコードが返ってきました
60
-
61
- ### 補足情報(FW/ツールのバージョンなど)
62
-
63
- Mac
64
- Google Colab
65
- selenium==4.1.0