티스토리 뷰
selenium을 이용해서 파일을 다운로드할때, 다운로드 받는 파일의 경로를 변경하고 싶었다.
이럴때, 아래와 같이 할 수 있다.
from selenium import webdriver
import time
testUrl = "http://localhost:8080/download/avocado-prices.zip"
driver = "/Users/akamikang/developer/lib/chromedriver"
screenshot_name = "my_mail_box.png"
options = webdriver.ChromeOptions()
#options.add_argument('headless')
options.add_argument("disable-gpu")
options.add_argument("lang=ko_KR") # 한국어!
options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
options.add_experimental_option("prefs", {
"download.default_directory": r"/Users/akamikang/developer/pythonworkspace/stock",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
driver = webdriver.Chrome(driver, chrome_options=options)
driver.set_window_size(1920, 1080)
driver.get(testUrl)
driver.implicitly_wait(3)
driver.get_screenshot_as_file(screenshot_name)
driver.implicitly_wait(3)
driver.save_screenshot(screenshot_name)
driver.quit()
자 이제 다운 받는 파일은 /Users/akamikang/developer/pythonworkspace/stock 에 쌓이게 된다.
이때 해당 파일을 원하는 이름으로 저장할 수 없을까?
당연히 저장이 가능하다.
shuttle 을 사용해서 위의 폴더에서 최근에 변경한 파일을 찾아 원하는 이름으로 변경하면 된다.
'개발 > Python' 카테고리의 다른 글
selenium + jupyter lab+python3 환경구성하기 (0) | 2020.03.10 |
---|---|
gitlab (0) | 2020.02.11 |
패쇄망에서 환경 구축하기 (0) | 2020.02.03 |
selenium 으로 화면 캡쳐하기 (0) | 2020.02.03 |
progress spin (0) | 2020.01.29 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- conda init
- jupyter lab
- elasticsearch
- pyenv
- __code__
- sorted
- python의 Reflection
- jqzip
- Lodash
- 동적클래스생성
- anaconda env
- MAC
- Restore
- vscode
- selenium #chromedriver
- pip freeze #패쇄망 #wheel
- inspect.py
- Selenium
- bootrap
- importlib
- covid19
- docker
- gitlab
- virturalenv
- jqgrid
- 호스트와 시간맞추기
- HashMap.getOrDefault
- redmine plugin
- zsh
- backup
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함