Web Crawling(웹 크롤링)_이미지 to pdf: with open~ 사용

juyeon·2022년 9월 13일
0

크롤링

목록 보기
13/13

밑바닥부터 시작하는 딥러닝 이미지 to pdf

# 1. import 라이브러리
import pandas as pd
import requests, json

# 2. path 경로 설정
path = 'C:\잡다\deeplearning_from_scratch_img'

# 3. for문 돌리기
for page in range(1, 315):
    url = f'https://online.fliphtml5.com/qvagj/edfm/files/large/{page}.jpg?1585412846'
    response = requests.get(url)
    
	# 4. with open ~ as file
    with open(f'{path}/{page}.png', "wb") as file: # image니까 "wb"
        file.write(response.content) # image니까 이렇게!
  • 파일 읽고 쓰기
f = open("foo.txt", 'w')
f.write("Life is too short, you need python")
f.close()
  • 이걸 with을 사용하면 이렇게 간단하게!
with open("foo.txt", "w") as f:
    f.write("Life is too short, you need python")
profile
내 인생의 주연

0개의 댓글