나는 기계 학습 프로젝트를 진행 중이며 내 프로그램을 훈련시킬 데이터 세트에 대한 많은 사진이 필요합니다. 웹 사이트 https://its.txdot.gov/ITS_WEB/FrontEnd/default.html?r=SAT&p=San%20Antonio&t=cctv 에는 6 분마다 업데이트되는 사진이 있습니다. Kyle Seal Pkwy의 LP 1604에 이미지를 저장해야하는데 방법을 알 수 없습니다. 이미지를 저장하기 위해 액션 체인을 사용하여 이미지를 마우스 오른쪽 버튼으로 클릭하려고합니다. 지금까지 내가 가진 내용은 다음과 같습니다.
driver.get('https://its.txdot.gov/ITS_WEB/FrontEnd/default.html?r=SAT&p=San%20Antonio&t=cctv')
time.sleep(5) #to let the site load
driver.find_element_by_id('LP-1604').click() #to get to the 1604 tab
time.sleep(5) #to let the site load
pic = driver.find_element_by_id('LP 1604 at Kyle Seale Pkwy__SAT')
action = ActionChains(driver)
action.context_click(pic)
일반적으로 마우스 오른쪽 버튼을 클릭하면 나타나는 드롭 다운 메뉴가 표시되지 않습니다. 우클릭보다 더 나은 방법이 있어야한다고 생각합니다. 6 분마다 실행되는 루프로 이것을 래핑하는 방법을 알고 있으므로 도움이 필요하지 않습니다. 이미지 부분을 다운로드하는 것입니다. 내가 겪는 문제 중 하나는 모든 이미지가 동일한 URL에 있고 대부분의 예제가 URL을 사용한다는 것입니다. 어떤 제안이라도 도움이 될 것입니다.
PC에 이미지를 저장하는 데 도움이 될 수 있다고 생각합니다.
from PIL import Image
def save_image_on_disk(driver, element, path):
location = element.location
size = element.size
# saves screenshot of entire page
driver.save_screenshot(path)
# uses PIL library to open image in memory
image = Image.open(path)
left = location['x']
top = location['y'] + 0
right = location['x'] + size['width']
bottom = location['y'] + size['height'] + 0
image = image.crop((left, top, right, bottom)) # defines crop points
image = image.convert('RGB')
image.save(path, 'png') # saves new cropped image
def your_main_method():
some_element_img = driver.find_element_by_xpath('//*[@id="id-of-image"]')
save_image_on_disk(driver, some_element_img, 'my-image.png')
time.sleep (6 * 60)을 사용해야하는 시간에 대해
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다