Skip to main content

使用python将html转化成json并部署到服务器

Project description

PHJF Alpha v0.0.5

  • 简单易懂的爬虫
  • 使用python将html转化成json并部署到服务器

>>注意<<: 如果想使用本库的全部内容,请至少达到能知道大多数Python3基础知识并且知道BeautifulSoup的基本用法和爬虫的概念和Flask库的基本知识

立志于用最简单的工作


为什么选择PHJF?

  • 简单
  • 轻便
  • 超强的可塑性
  • 一键部署

实现的功能

  • 模块化
  • 算是debug
  • 保存为json并且格式化
  • 键部署到本地服务器

未实现的功能

  • 部署到真正意义上的互联网服务器
  • 爬虫未响应自动结束程序
  • 部署到服务器时进行格式化

迅速开始

使用pip下载 pip3 install PHJF

注意:所依赖的第三方库

  • BeautifulSoup
  • Flask

库地址:PHJF in Github


快速入门

最简单的项目

创建main.py

注意:必须是main.py

get_page(url, encoding, 工作模式)

获取页面,拥有三种工作模式

  • url : 输入您所需要爬虫的网页
  • encoding : 编码格式,默认为 utf-8
  • 工作模式 : 见下文

工作模式的选择

  • let : 对接页面数据,解析时使用
  • save : 保存页面到当前目录

玩法实例

爬取baidu.com的数据并保存

from PHJF import *

def main():
  get_page("https://baidu.com", "", "save")

if __name__ == "__main__"
  main()

进阶玩法

from PHJf import *


def data(page_text, lists_info):
    soup = BeautifulSoup(page_text, 'lxml')
    # 在这里写入你需要的
    lists_info.append({})


def main():
    get_page("", "", "")
    run_compile_page("", "")
    run_server()


if __name__ == "__main__":
    main()

data()

不要改变data()里的内容

  • data 函数用来注入soup来编译html
  • lists_info.append({}) 用来放置输出,未来将会编译成中文json

比如

def data(page_text, lists_info):
    soup = BeautifulSoup(page_text, 'lxml')
    page_list = soup.select('.Revision_list > ul > li')
    for each in page_list:
        image = each.find("img")
        image_url = image['data-original']
        title = each.find("a", attrs={"class": "bt"})
        text = each.find("div", attrs={"class": "miaoshu"}).text
        data = each.find("span", attrs={"class": "time"}).text
        lists_info.append({"image": image_url, "title": title.text, "text": text, "data": data})

run_compile_page(工作模式, 文件名字)

工作模式

  • json : 保存页面到当前目录
  • data : 为运行本地服务器对接数据

文件名字

  • 为你的本地服务器设置目录名称与保存文件时的名称

run_server()

  • 启动本地服务器

常见问题

  • Q:爬虫爬不动了
    A:重新启动程序

*来自 邱璇洛 2022 ©*️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PHJF-0.0.5.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PHJF-0.0.5.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file PHJF-0.0.5.2.tar.gz.

File metadata

  • Download URL: PHJF-0.0.5.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for PHJF-0.0.5.2.tar.gz
Algorithm Hash digest
SHA256 26a35940f3c88b3de5493160e22ef0f839f4986e3d92dbe3b88044c456d2980c
MD5 59a0b882d327454d490734fed79d4e8f
BLAKE2b-256 559a5f82b7701b6d385f94d9623e994bf3a8330ad642b49d3bec381c01536baf

See more details on using hashes here.

File details

Details for the file PHJF-0.0.5.2-py3-none-any.whl.

File metadata

  • Download URL: PHJF-0.0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for PHJF-0.0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fcd8540296f607a2bd83342350e99d8c5ca73b2e87b0667b6b19d024e853feb1
MD5 6cb89c8ba8cbefff002f4f0b560468d5
BLAKE2b-256 ddad9ec67814de365602c313ef212e60b614658bd5abe2fc35f764b9c37c689d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page