https://www.instagram.com/p/B9MjyquAfkE/ 로 이동하여 볼 수있는 이미지 + 코멘트 블록의 스크린 샷을 찍고 저장하려고합니다 . 아래는 내 코드의 테스트 가능한 부분입니다.
오류가 발생합니다 :
article.screenshot_as_png ( 'article.png') TypeError : 'bytes'object is not callable
코드로 기사를 찾을 수있는 것 같지만 스크린 샷에 문제가 있습니다. 또한 내 컴퓨터에서 스크린 샷을 저장할 특정 위치를 지정하려고합니다.
from selenium import webdriver
import time
class bot:
def __init__(self):
self.driver = webdriver.Chrome("path to chrome driver here")
def screenShot(self):
driver = self.driver
driver.get("https://www.instagram.com/p/B9MjyquAfkE/")
time.sleep(2)
#find post+comments block on page
article = driver.find_elements_by_xpath('//div[@role="dialog" or @id="react-root"]//article')[-1]
#take screenshot of the post+comments block
article.screenshot_as_png('article.png')
if __name__ == "__main__":
bot = bot()
bot.screenShot()
대신 시도
article.screenshot_as_png('article.png')
이:
screenshot_as_bytes = article.screenshot_as_png
with open('article.png', 'wb') as f:
f.write(screenshot_as_bytes)
설명:
article.screenshot_as_png
이미 바이트 단위의 스크린 샷이므로 저장하기 만하면됩니다. article.screenshot_as_png()
다음 과 같이 호출 하려고하면 바이트에서 실행이 시도되므로 오류가 발생합니다.TypeError: 'bytes' object is not callable
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다