Automate Webpage PDF Conversion in Python in 3 Easy Steps
You know when you're surfing the web and you think, 'I want to save this page. What do I do?'Can't I turn a webpage into a PDF file? You're not Terry from IT Playground if you just say "look at the post"! webtopdf.com Let's move beyond the easy stuff that anyone can do if they know how to do it, and dive into the deeper world of Python automation programming.
Getting started
In fact, many of you are allergic to the word programming, coding, and so on. In fact, the source code is now done by the AI service, and we just need to know how to take it and run it. The most important thing is Ideas for what to automateI think it is.
In fact, even if you use AI services such as Allen, Litton, Claude 3, etc., you still have to go back and forth several times unless it is easy coding. Even if you run the AI-generated code through a program like VS Code, I think it takes about 10-20% to succeed in the desired function at once.
Okay, that was a long introduction, so let's get started.
Python Automation CodeSource
# 파이썬 자동화 코드소스
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# URL 목록 (필요에 따라서 원하는 만큼 목록 생성하기)
urls = ["https://namu.wiki/w/Python?from=%ED%8C%8C%EC%9D%B4%EC%8D%AC", "https://namu.wiki/w/Visual%20Studio%20Code?from=VS%20Code"]
# 각 URL에 대해 반복
for url in urls:
# Chrome 드라이버 설정
driver = webdriver.Chrome()
# webtopdf.com 페이지 열기
driver.get("https://webtopdf.com/")
# 페이지가 로드될 때까지 기다리기
time.sleep(1)
# 검색 상자 찾기 및 URL 입력
search_box = driver.find_element("name", "textfield")
search_box.clear()
search_box.send_keys(url)
# 변환 버튼 클릭
convert_button = driver.find_element("id", "btnConvert")
convert_button.click()
# 변환이 완료될 때까지 기다리기 (필요에 따라 시간(초) 조절)
time.sleep(30)
# 다운로드 버튼 클릭
download_button = driver.find_element("css selector", ".downfile_over")
download_button.click()
# pdf파일이 다운로드 완료될 때까지 기다리기 (필요에 따라 시간(초) 조절)
time.sleep(30)
# 브라우저 닫기
driver.quit()I'm going to start by looking at the results, and I don't know if you're really good at prompting and getting what you want, but for most people this is easier said than done, so I'm just going to run it with the finished source code that I ended up with.
And if you want to dive deeper, I hope you'll continue to study this post. (It's more fun than you think. I used to shake my head when I coded, but now I'm getting a rush from AI. Coding + AI, it's an adrenaline rush).
Paste and run the source code
First, copy and paste the above source code into VS Code as shown below. If you don't have VS Code installed, go to the Installing VS CODE - Windows post for more information. If you look at the 6th line of the source code, you will see a list of URLs. Copy the website address you want and type "website address1", "website address2", ... and so on. Then click the magic button on the top right (Run button ▷).

Then, magically, my computer launches the Chrome web browser on its own, and I go to 'webtofeedf.com' and type in the website address I want to save and download the page as a pdf file. I'll post about it later, but even typing in the 'URL List' insertion is a real treat.
For reference, the list of URLs in this source code are the introductory pages on TreeWiki. There's one for Python and one for VS Code. If it converts well to PDF, it's worth a read.
Things to consider
At the same time, the 'Type a website address' with 'webtofeedf.com' to convert this website to a pdf file as 'Time to convert' and the converted PDF file to 'Download time' settings. These times vary depending on the text, pictures, etc. that make up the webpage, but I've had no problems with both in about 30 seconds or so. (In some cases, I've had downloads take 40+ seconds, but that's because of the wires in my apartment building...)
Organize
I unintentionally became an advertisement for webtopdf service, but since they provide unlimited service for free, I think they should do this service to make a living. There are many sites that limit the number of pdf conversions. I apologize. In this post, I created an automation system that automatically converts a webpage to a pdf file when executed by pasting the python source code. I will talk about the process principle in the form of an addendum to this post or a new post soon.
Today we've talked about something that's a little deep, but not too hard to implement. Until the day comes when our lives are enriched by increased IT knowledge. Life2.0: IT Playground Terrywill continue to run.
Thank you.
Appendix. AI that reads your source code
The source code and comments below are the result of trying to interpret the generative AI. If you are reading this post, please try to interpret the source code above. Rather than asking them to interpret it, give them a role and say, "You're a Python expert now." and try it. If you don't understand something, ask for a more detailed explanation. After a few steps, you should be able to understand more than 50%.
####### Sponsored by Claude.ai
This code performs the function of downloading a webpage as a PDF file from a given list of URLs via web automation. We'll explain the code step by step below.
# 필요한 라이브러리 및 모듈 임포트
from selenium import webdriver # 웹 브라우저 자동화를 위한 Selenium 라이브러리
from selenium.webdriver.common.keys import Keys # 키보드 입력을 자동화하기 위한 Keys 모듈
import time # 시간 지연을 위한 time 모듈
# URL 목록 선언 및 초기화
# 목록에 PDF로 변환하고자 하는 웹페이지 URL을 추가할 수 있음
urls = ["https://namu.wiki/w/Python?from=%ED%8C%8C%EC%9D%B4%EC%8D%AC",
"https://namu.wiki/w/Visual%20Studio%20Code?from=VS%20Code"]
# 각 URL에 대해 반복 처리
for url in urls:
# Chrome 웹 드라이버 실행
driver = webdriver.Chrome()
# webtopdf.com 페이지 열기
driver.get("https://webtopdf.com/")
# 페이지가 완전히 로드될 때까지 1초 대기
time.sleep(1)
# #1 웹페이지의 URL 입력 상자 찾기 및 URL 입력
search_box = driver.find_element("name", "textfield")
search_box.clear() # 입력상자 초기화
search_box.send_keys(url) # URL 입력
# #2 변환 버튼 클릭
convert_button = driver.find_element("id", "btnConvert")
convert_button.click()
# #3 변환 작업이 완료될 때까지 30초 대기
time.sleep(30)
# #4 다운로드 버튼 클릭
download_button = driver.find_element("css selector", ".downfile_over")
download_button.click()
# #5 PDF 파일 다운로드가 완료될 때까지 30초 대기
time.sleep(30)
# #6 Chrome 드라이버 종료
driver.quit()Step-by-step description
- Locate the URL entry box for the webpage and enter the given URL.
- Click the Convert button to start converting the webpage to a PDF file.
- Wait 30 seconds for the PDF conversion to complete.
- When the conversion is complete, click the Download button to start downloading your PDF file.
- Wait 30 seconds for the PDF file to finish downloading.
- When you're done, exit the Chrome driver.
This code uses a loop to convert and download all webpages in a list of URLs to PDF files. The execution time may vary depending on the size of the webpage and your internet speed. We've explained each step in detail so that even beginners can understand it.
All content on 'secondlife.lol' is protected by copyright law. Unauthorized reprinting, copying, distribution, etc. is prohibited.





