1. import requests, os
    2. # 1.起始URL地址
    3. start_url = ''
    4. # 2.发送请求,获取响应
    5. response = requests.get(start_url)
    6. # 3.解析响应,数据提取
    7. data = response.content
    8. # 4.保存
    9. with open('1.jpg', 'wb') as f:
    10. f.write(data)
    1. from urllib.parse import quote
    2. title = quote(input("请输入你想要浏览的贴吧主题:"))
    3. print(title)
    4. >>> 请输入你想要浏览的贴吧主题:王者荣耀
    5. >>> %E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80
    1. import requests, os
    2. from urllib.parse import quote
    3. # 1.起始URL地址
    4. """
    5. https://tieba.baidu.com/f?kw= %E5%A5%94%E9%A9%B0
    6. https://tieba.baidu.com/f?kw=%E5%A5%94%E9%A9%B0&pn=50
    7. """
    8. title = input("请输入你想浏览的贴吧主题:")
    9. title_1 = quote(title)
    10. page = int(input("请输入需要浏览的页码:"))
    11. for i in range(int(page)):
    12. start_url = f'https://tieba.baidu.com/f?kw={title_1}&pn={i * 50}'
    13. # 2.发送请求,获取响应
    14. response = requests.get(start_url)
    15. # 3.解析响应,数据提取
    16. data = response.content.decode()
    17. # 4.保存
    18. os_path = f'E:/同步空间/Python/Reptile/Data/百度贴吧/{title}分类/'
    19. if not os.path.exists(os_path):
    20. os.mkdir(os_path)
    21. with open(os_path + title + str(i) + '.html', 'w', encoding='utf-8') as f:
    22. f.write(data)
    23. print(f'百度贴吧==={title}分类===第{i+1}页保存完成')
    1. pyinstaller -F 文件名