回答編集履歴

2

コードに問題があるようなので 削除

2020/08/30 10:14

投稿

Reach
Reach

スコア735

test CHANGED
@@ -1,73 +1 @@
1
- 駄目かも‥
2
-
3
-
4
-
5
- ```Python
6
-
7
- from selenium import webdriver
8
-
9
- from bs4 import BeautifulSoup
10
-
11
- import time
12
-
13
-
14
-
15
-
16
-
17
- option = webdriver.ChromeOptions()
18
-
19
- option.add_argument('--headless')
20
-
21
- option.add_argument('--disable-extensions')
22
-
23
- option.add_argument('--disable-gpu')
24
-
25
- option.add_argument('--lang=ja-JP')
26
-
27
- option.add_argument("start-maximized")
28
-
29
- option.add_argument("--disable-dev-shm-usage")
30
-
31
- option.add_experimental_option("excludeSwitches", ["enable-automation"])
32
-
33
- option.add_experimental_option('useAutomationExtension', False)
34
-
35
- option.add_argument("--disable-blink-features=AutomationControlled")
36
-
37
- option.add_argument("--no-referrers")
38
-
39
- option.add_argument(r'--user-data-dir=C:\Users\【ユーザー名】\AppData\Local\Google\Chrome\User Data')
40
-
41
-
42
-
43
- driver = webdriver.Chrome(r"C:/chromedriver/chromedriver.exe", options=option)
44
-
45
- driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
46
-
47
- driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/82.0.4071.0 Safari/537.36'})
48
-
49
-
50
-
51
- time.sleep(5)
1
+ --headlessは 難しいかもです
52
-
53
- url = 'xxx'
54
-
55
- driver.get(url)
56
-
57
- time.sleep(5)
58
-
59
- print(driver.title)
60
-
61
- html = driver.page_source.encode('utf-8')
62
-
63
-
64
-
65
- soup = BeautifulSoup(html,'lxml')
66
-
67
-
68
-
69
- print(soup)
70
-
71
- driver.quit()
72
-
73
- ```

1

重複削除

2020/08/30 10:14

投稿

Reach
Reach

スコア735

test CHANGED
@@ -36,10 +36,6 @@
36
36
 
37
37
  option.add_argument("--no-referrers")
38
38
 
39
- option.add_argument('--lang=ja-JP')
40
-
41
- option.add_argument('--disable-extensions')
42
-
43
39
  option.add_argument(r'--user-data-dir=C:\Users\【ユーザー名】\AppData\Local\Google\Chrome\User Data')
44
40
 
45
41