小编Dan*_*any的帖子

使用 Confluence Cloud API 发布文章时忽略 HTML 格式

我正在尝试使用 REST API 发布有关 Confluence 的文章。

当我以存储格式准备文章时,我会像缩进 HTML 代码一样缩进内容,并使用换行符和空格。问题是,当文章发布时,所有这些换行符和空格都会被保留,就好像我使用了<br/>不间断的空格符号一样。

例如,如果我发送这样的内容:

<p>First part of paragraph 
    <ac:link ac:anchor="4b14531b1624f2b">
        <ri:page ri:content-title="Test Article"></ri:page>
        <ac:plain-text-link-body><![CDATA[link caption]]></ac:plain-text-link-body>
    </ac:link>
 last part of paragraph.</p>
Run Code Online (Sandbox Code Playgroud)

在页面上的渲染是这样的:

First part of paragraph
    link caption
last part of paragraph.
Run Code Online (Sandbox Code Playgroud)

但我期望这样:

First part of paragraph link caption last part of paragraph.
Run Code Online (Sandbox Code Playgroud)

是否可以像普通 HTML 一样告诉 confluence 忽略空格?也许管理员可以更改一些设置?

如果我通过Web编辑器正常创建页面,然后通过API调用获取其内容,则所有返回的内容都在一行上。这太愚蠢了。

我以前使用过的 Confluence 服务器从未遇到过这个问题。

我使用的是 Confluence Cloud 版本。

confluence confluence-rest-api

6
推荐指数
0
解决办法
244
查看次数

标签内的美丽汤标签

我正在尝试添加一个新链接作为无序列表元素。

但是我不能在另一个带有 Beautiful Soup 的标签中添加标签。

with open('index.html') as fp:
    soup = BeautifulSoup(fp, 'html.parser')

a = soup.select_one("id[class=pr]")
ntag1 = soup.new_tag("a", href="hm/test")
ntag1.string = 'TEST'
... (part with problem)
a.insert_after(ntag2)
Run Code Online (Sandbox Code Playgroud)

ntag1 必须留在里面"<li>",所以我试过了

   ntag2 = ntag1.new_tag('li')  
   TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)

带包装()

 ntag2 = ntag1.wrap('li')
   ValueError: Cannot replace one element with another when theelement to be replaced is not part of a tree.
Run Code Online (Sandbox Code Playgroud)

原始 HTML

<id class="pr">
    </id>
    <li>
     <a href="pr/protocol">
      protocol
     </a>
Run Code Online (Sandbox Code Playgroud)

理想的 html 输出

<id class="pr">
</id>
<li> …
Run Code Online (Sandbox Code Playgroud)

beautifulsoup python-3.x

5
推荐指数
1
解决办法
2703
查看次数

可视化PyCharm中的点文件

我已经生成了一个点文件以使用代码可视化决策树

import numpy as np
from sklearn.model_selection import train_test_split
import sklearn.tree
from sklearn.datasets import load_breast_cancer

cancer = load_breast_cancer()
X_train, X_test, y_train, y_test =train_test_split(cancer.data,cancer.target, stratify=cancer.target, random_state=42)
tree = sklearn.tree.DecisionTreeClassifier(random_state=0,max_depth=4)
tree.fit(X_train,y_train)
sklearn.tree.export_graphviz(tree,out_file="tree.dot",class_names=cancer.target_names,feature_names=cancer.feature_names,impurity=False, filled=True)
Run Code Online (Sandbox Code Playgroud)

这将成功创建tree.dot文件。我现在可以使用graphviz的dot.exe实用工具生成一个png文件(https://graphviz.gitlab.io/_pages/Download/Download_windows.html

from subprocess import check_call
check_call(['...PATH_TO_GRAPHVIZ/graphviz-2.38/release/bin/dot.exe','-Tpng','tree.dot','-o','tree.png'])
Run Code Online (Sandbox Code Playgroud)

我也想在PyCharm中可视化决策树。有没有办法做到这一点?

dot graphviz pycharm

5
推荐指数
1
解决办法
478
查看次数

foo:'bar'| 冒号在这个python表达式中做了什么?

我刚刚偶然发现了python解释器的奇怪行为.错误印刷,我在声明变量时放置了冒号而不是等号.

Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
>>> foo: 'bar'
>>>
Run Code Online (Sandbox Code Playgroud)

之前没有声明变量foo.令人惊讶的是,Python没有抛出异常,但也没有做任何其他事情.

这是某种新语法吗?它的目的是什么?


PS Python 2.7按预期抛出异常:

Python 2.7.10 (default, Aug 17 2018, 17:41:52)
>>> foo: 'bar'
  File "<stdin>", line 1
    foo: 'bar'
       ^
SyntaxError: invalid syntax
>>>
Run Code Online (Sandbox Code Playgroud)

python syntax colon

5
推荐指数
0
解决办法
41
查看次数

如何从树中删除 NavigableString?

我有点困惑:所有标签都有一种decompose()方法可以将标签从树中移除。但是如果我想删除 aNavigableString呢?它没有这样的方法:

>>> b = BeautifulSoup('<p>aaaa <span> bbbbb </span> ccccc</p>', 'html.parser')
>>> b.p.contents[0]
'aaaa '
>>> type(b.p.contents[0])
<class 'bs4.element.NavigableString'>
>>> b.p.contents[0].decompose()
Traceback (most recent call last):
...
AttributeError: 'NavigableString' object has no attribute 'decompose'
Run Code Online (Sandbox Code Playgroud)

有一种方法我设法NavigableString从树中删除了:通过从内容列表中删除它:

>>> b.p.contents.pop(0)
'aaaa '
>>> b
<p><span> bbbbb </span> ccccc</p>
Run Code Online (Sandbox Code Playgroud)

问题是它仍然存在于strings方法响应中:

>>> list(b.strings)
['aaaa ', ' bbbbb ', ' ccccc']
Run Code Online (Sandbox Code Playgroud)

这表明这是错误的做法。此外,我strings在我的代码中使用,所以这个 hacky 解决方案是不可接受的,唉。


所以问题是:如何NavigableString从树中删除特定对象?

python beautifulsoup

5
推荐指数
1
解决办法
973
查看次数

DOT 可以生成更结构化的图表吗?

我不太确定如何描述我的客户想要什么,所以我会让一张图片来说明大部分内容。我正在使用 DOT 来生成或多或少的物料清单问题的图表。(显示所有级别的传入批次和所有传出批次,这些批次是根据传入批次中的材料创建的。)我已经获得了创建包含适当结构化数据的图表的代码。例如,我生成这个GV文件:

digraph LotTrc {
  rankdir=LR;
  graph[label="Lot #AD626", labelloc=top, labeljust=left, fontsize=24];
   PO_AD626_0000003333[shape=triangle,color=greenyellow,style=filled,label=AD626];
   AJ_AD626_SJ00000099[shape=circle,color=red2,style=filled,label=AD626];
   PO_AD626_0000003333  -> AJ_AD626_SJ00000099;
   AJ_AD626_SJ00000103[shape=circle,color=red2,style=filled,label=AD626];
   PO_AD626_0000003333  -> AJ_AD626_SJ00000103;
   WO_AD627_RE00002230[shape=ellipse,color=lemonchiffon,style=filled,label=AD627];
   PO_AD626_0000003333  -> WO_AD627_RE00002230;
   SO_AD627_OZ00025429[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025429;
   SO_AD627_OZ00025434[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025434;
   SO_AD627_OZ00025439[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025439;
   SO_AD627_OZ00025444[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025444;
   WO_AD628_RE00002231[shape=ellipse,color=lemonchiffon,style=filled,label=AD628];
   PO_AD626_0000003333  -> WO_AD628_RE00002231;
   SO_AD628_OZ00025430[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025430;
   SO_AD628_OZ00025435[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025435;
   SO_AD628_OZ00025440[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025440;
   SO_AD628_OZ00025445[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025445;
   WO_AD629_RE00002232[shape=ellipse,color=lemonchiffon,style=filled,label=AD629];
   PO_AD626_0000003333  -> WO_AD629_RE00002232;
   SO_AD629_OZ00025431[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025431;
   SO_AD629_OZ00025436[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025436;
   SO_AD629_OZ00025441[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025441;
   SO_AD629_OZ00025446[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> …
Run Code Online (Sandbox Code Playgroud)

dot graphviz

4
推荐指数
1
解决办法
792
查看次数

如何确定Graphviz可执行文件在系统的PATH中?

我正在Sublime Text 3上使用Python 3使用Graphviz。运行此代码时:

data = tree.export_graphviz(dtGini[55], out_file = None)
graph = graphviz.Source(data)
graph.render("testingthis")
Run Code Online (Sandbox Code Playgroud)

我得到这些错误:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'testingthis'], make sure the Graphviz executables are on your systems' PATH
Run Code Online (Sandbox Code Playgroud)

似乎找不到所需的文件。在Sublime Text 3中,我对Conda的用户设置是:

data = tree.export_graphviz(dtGini[55], out_file = None)
graph = graphviz.Source(data)
graph.render("testingthis")
Run Code Online (Sandbox Code Playgroud)

我可以从控制面板中获取以下环境变量:

C:\ProgramData\Miniconda3\Scripts\
C:\ProgramData\Miniconda3\
C:\ProgramData\Miniconda3\conda-meta\history
C:\Users\X\AppData\Local\conda\conda\pkgs
C:\Users\X\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
C:\Users\X\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\dot.exe
Run Code Online (Sandbox Code Playgroud)

在Anaconda提示符下,当我输入Python时,按Enter键,然后输入“ import graphviz”,我没有收到任何错误。在Sublime Text 3中,如果我只有诸如graph.py之类的文件

import graphviz
Run Code Online (Sandbox Code Playgroud)

它执行没有任何错误。 …

python graphviz scikit-learn anaconda

1
推荐指数
2
解决办法
4565
查看次数

如何注释查询集添加按字段分组的行号?

我有两个模型:

范本[id 书名、author_id]

模型作者[id, 姓名]

我需要查询按作者姓名和书名排序的书籍:

result = Books.order_by('author__name', 'title').value_list('author__name', 'title')
Run Code Online (Sandbox Code Playgroud)

但我还需要在每一行添加一个计数器,该计数器将随着每个新作者的出现而重置。

查询的结果应该是:

title      name                  position
-----------------------------------------
book1      Dan Brown             1
book2      Douglas Adams         1
book3      Douglas Adams         2
book4      Douglas Adams         3
book5      Douglas Adams         4
book6      Ernest Hemingway      1
book7      Ernest Hemingway      2
book8      Ernest Hemingway      3
book9      John Steinbeck        1
book10     John Steinbeck        2
Run Code Online (Sandbox Code Playgroud)

是否可以position使用 Django ORM 来实现该字段?

django orm

1
推荐指数
1
解决办法
3003
查看次数