分类 python 下的文章

windows服务器安装jupyter lab并设置外网访问

一、下载安装python

https://www.python.org/

二、安装jupyter lab

安装jupyter lab

pip install jupyterlab -i https://pypi.tuna.tsinghua.edu.cn/simple

安装中文语言包

pip install jupyterlab-language-pack-zh-CN

三、设置外网访问

查看jupyter lab设置文件目录

jupyter --config-dir

生成jupyter lab设置文件(jupyter_lab_config.py)

jupyter lab --generate-config

生成密码

# 打开python,输入以下代码,按要求数据密码即可,输入过程中不显示
# 将生成的密码摘要复制到配置文件password的''中
from jupyter_server.auth import passwd
passwd()

修改配置文件

# 可以在jupyter_lab_config.py后面添加或者取消原文件中注释后修改
# ip可以设置成本底ip或者*
# notebook_dir根据自己开发环境修改
# port端口根据需要自己修改
# password通过python生成
# windows系统路径要用双斜杠\\
c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '*'
c.ServerApp.open_browser = False
c.ServerApp.notebook_dir = '/home/username/target path/'
c.ServerApp.port = 9527
c.ServerApp.password = ''

安装代码提示插件

pip install jupyterlab-lsp

启动jupyter lab

jupyter lab

这浏览器中输入服务器IP:port,输入密码,修改语言即可

BeautifulSoup修改text值

注意:target.text能获取text的值,但是无法修改text值,要用target.string修改

from bs4 import BeautifulSoup
import os

with open("index.html","r",encoding="utf-8") as htmlfile:
    html=htmlfile.read()
    soup = BeautifulSoup(html, 'lxml')  #生成BeautifulSoup对象
    targets = soup.find_all('a') #所有名称为a的节点
    for target in targets:
        #此地不能用target.text
        target.string="中卫日报("+target["href"][27:37]+")"
        htfile=os.path.join(os.getcwd(),target["href"])
        print(htfile)
        #if os.path.exists(htfile):
        #    target["style"]="color:red;"
        #else:
        #    target["style"]="color:green;"

with open("index.html","w") as fp:
    fp.write(soup.prettify())