# LXF-Python-Tutorial **Repository Path**: iluvchang/LXF-Python-Tutorial ## Basic Information - **Project Name**: LXF-Python-Tutorial - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-17 - **Last Updated**: 2025-10-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LXF Python Tutorial ## 简介 本项目通过爬虫下载 [廖雪峰Python教程](https://www.liaoxuefeng.com/wiki/1016959663602400) ,并将下载的markdown文件转化为LaTeX,最终编译成PDF。 ## 前言 最近在看廖雪峰老师的[Python教程](https://www.liaoxuefeng.com/wiki/1016959663602400),个人感觉写得非常简炼,并且还有在线编程练习,于是产生了将其整理成PDF方便离线查看的想法。 > 下载链接为:https://github.com/Theigrams/LXF-Python-Tutorial/releases/tag/1.0 整个过程一共分为两步: 1. 将网页内容下载成markdown文件 2. 将markdown文件转化成LaTeX,然后编译成PDF ## 爬虫下载 ### 获取网址 首先,我们要找到全部的网址,先进入首页https://www.liaoxuefeng.com/wiki/1016959663602400,然后F12进入开发者模式。 ![image-20210216214024925](http://pic.theigrams.cn/20210216214032.png?imagslim) 然后查看侧边栏的目录,其 `class="uk-nav uk-nav-side"`,于是用爬虫获取对应信息,因为该网站开启了反爬机制,所以要加上一个headers信息。 ```python from bs4 import BeautifulSoup as bs import requests headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'} response = requests.get("https://www.liaoxuefeng.com/wiki/1016959663602400",headers = headers) soup = bs(response.content, "html.parser") menu_tag = soup.find_all(class_="uk-nav uk-nav-side")[1] ``` `menu_tag` 中储存的内容如下: ```html >>> print(menu_tag)