小编Anv*_*oad的帖子

纸张的RGB或html颜色

我试图从平装小说中找到纸张的颜色.也许这是一个愚蠢的问题,但我正忙于一个程序,在我的业余时间提供大量的页面供用户阅读,我正在寻找一个熟悉的平装小说的舒适熟悉的颜色.我的扫描仪似乎漂白了我试图采样的页面.(现在寻找一个羞怯的表情)

colors

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

有没有办法在lxml中禁用锚属性的urlencoding

我正在使用lxml 2.2.8并尝试将一些现有的html文件转换为django模板.我唯一的问题是lxml urlencodes锚名称和href属性.例如:

<xsl:template match="a">
<!-- anchor attribute href is urlencoded but the title is escaped -->
<a href="{{{{item.get_absolute_url}}}}" title="{{{{item.title}}}}">
    <!-- name tag is urlencoded -->
    <xsl:attribute name="name">{{item.name}}</xsl:attribute>
    <!-- but other attributes are not -->
    <xsl:attribute name="nid">{{item.nid}}</xsl:attribute>
    <xsl:attribute name="class">{{item.class_one}}</xsl:attribute>
    <xsl:apply-templates/>
</a>
Run Code Online (Sandbox Code Playgroud)

像这样产生html:

<a href="%7B%7Bitem.get_absolute_url%7D%7D"  
   title="{{item.title}}" name="%7B%7Bitem.name%7D%7D" 
   nid="{{item.nid}}" class="{{item.class_one}}">more info</a>
Run Code Online (Sandbox Code Playgroud)

我想要的是这个:

<a href="{{item.get_absolute_url}}">more info</a>
Run Code Online (Sandbox Code Playgroud)

有没有办法禁用lxml正在做的(自动)urlencoding?

这里(基本上)是我用来生成和解析文件的代码:

from lxml import etree, html
from StringIO import StringIO

doc = StringIO(
'''<html>
<head>
    <title>An experiment</title>
</head>
<body>
<p class="one">This is an interesting paragraph detailing …
Run Code Online (Sandbox Code Playgroud)

python xslt lxml urlencode

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

用xslt构建django模板文件

我有大约4,000个html文档,我试图使用xslt转换为django模板.我遇到的问题是,当我尝试在属性标记中包含模板变量时,xslt正在转义模板变量的'{'花括号; 我的xslt文件如下所示:

<xsl:template match="p">
    <p>
        <xsl:attribute name="nid"><xsl:value-of select="$node_id"/></xsl:attribute>
        <xsl:apply-templates select="*|node()"/>
    </p>
    <span>
        {% get_comment_count for thing '<xsl:value-of select="$node_id"/>' as node_count %}
        <a href="">{{ node_count }}</a> //This works as expected
    </span>
    <div>
        <xsl:attribute name="class">HControl</xsl:attribute>
        <xsl:text disable-output-escaping="yes">{% if node_count > 0 %}</xsl:text> // have to escape this because of the '>'
        <div class="comment-list">
            {% get_comment_list for thing '<xsl:value-of select="$node_id"/>' as node_comments %}
            {% for comment in node_comments %}
            <div class="comment {{ comment.object_id }}"> // this gets escaped
                <a>
                <xsl:attribute name="name">c{{ comment.id }}</xsl:attribute> …
Run Code Online (Sandbox Code Playgroud)

xslt lxml escaping django-templates

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

标签 统计

lxml ×2

xslt ×2

colors ×1

django-templates ×1

escaping ×1

python ×1

urlencode ×1