本文整理汇总了Python中pyquery.PyQuery.outer_html方法的典型用法代码示例。如果您正苦于以下问题:Python PyQuery.outer_html方法的具体用法?Python PyQuery.outer_html怎么用?Python PyQuery.outer_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyquery.PyQuery
的用法示例。
在下文中一共展示了PyQuery.outer_html方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_attribute_to_document
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outer_html [as 别名]
def test_render_attribute_to_document():
document = PyQuery('<a attribute="{ value }" data-riot-id="0"></a>')
expression = {'expression': '{ value }', 'attribute': 'attribute', 'type': 'attribute', 'node': document}
render_document([expression], {'value': 'value'})
assert document.outer_html() == '<a attribute="value" data-riot-id="0" data-riot-dirty="true"></a>'
render_document([expression], {'value': 1})
assert document.outer_html() == '<a attribute="1" data-riot-id="0" data-riot-dirty="true"></a>'
示例2: test_render_markup_to_document
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outer_html [as 别名]
def test_render_markup_to_document():
document = PyQuery('<custom data-riot-id="0"><text data-riot-id="0.0"><span class="name">{ name}</span><span class="greet">{ greet }</span></text></custom>')
expressions = parse_document_expressions(document)
render_document(expressions, {'name': '@ainesmile', 'greet': 'I love you.'})
assert document.outer_html() == '<custom data-riot-id="0" data-riot-dirty="true"><text data-riot-id="0.0" data-riot-dirty="true"></text></custom>'
assert expressions[0]['value'] == [(u'name', '@ainesmile'), (u'greet', 'I love you.')]
render_document(expressions, {'name': '@soasme', 'greet': 'I love you, too.'})
assert expressions[0]['value'] == [(u'name', '@soasme'), (u'greet', 'I love you, too.')]
示例3: refineLocal
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outer_html [as 别名]
def refineLocal():
with open(os.path.join(savefolder, "downloads.html"), "r", encoding="utf8") as f:
html = PyQuery(f.read())
cmd = ""
for item in html("li button"):
dl_url = item.get("data-clipboard-text").split(" ")[1]
cmd += "{}\n".format(item.get("data-clipboard-text"))
if os.path.exists(os.path.join(savefolder, os.path.basename(urllib.parse.urlsplit(dl_url).path))):
item.set("class", "btn downloaded")
else:
item.set("class", "btn")
with open(os.path.join(savefolder, "downloads-refined.html"), "w+", encoding="utf-8") as wf:
wf.write(html.outer_html())
subprocess.Popen(["explorer", os.path.join(savefolder, "downloads-refined.html")])
with open(os.path.join(savefolder, "wwdc2016.sh"), "w+", encoding="utf8") as f:
f.write(cmd[:-2])
示例4: convert_image_links
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outer_html [as 别名]
def convert_image_links(self, url: str, html: str):
"""
replace image src from relative url to absolute url
"""
doc = PyQuery(html)
images = doc.find("img").items()
for image in images:
src = image.attr("src")
abs_url = urllib.parse.urljoin(url, src)
if self.exclude_image_url_pattern and re.match(self.exclude_image_url_pattern, abs_url):
self.logger.info("skiping %s", abs_url)
image.remove_attr("src")
image.attr("alt", "excluded image")
else:
ext = get_url_ext(abs_url)
save_to = "{}{}".format(md5_digest(abs_url), ext)
image.attr("src", save_to.replace(".svg", ".png"))
self.images.add((abs_url, save_to))
return doc.outer_html()
示例5: scanRemote
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outer_html [as 别名]
#.........这里部分代码省略.........
ZXcgVHlwZUVycm9yKCJDYW5ub3QgY2FsbCBhIGNsYXNzIGFzIGEgZnVuY3Rpb24iKX1mdW5jdGlv
biBjKHQsZSl7aWYoIXQpdGhyb3cgbmV3IFJlZmVyZW5jZUVycm9yKCJ0aGlzIGhhc24ndCBiZWVu
IGluaXRpYWxpc2VkIC0gc3VwZXIoKSBoYXNuJ3QgYmVlbiBjYWxsZWQiKTtyZXR1cm4hZXx8Im9i
amVjdCIhPXR5cGVvZiBlJiYiZnVuY3Rpb24iIT10eXBl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b24uZGVz
dHJveSgpLHRoaXMuY2xpcGJvYXJkQWN0aW9uPW51bGwpfSxlfSh1LmRlZmF1bHQpO3QuZXhwb3J0
cz1kfSl9LHsiLi9jbGlwYm9hcmQtYWN0aW9uIjo4LCJnb29kLWxpc3RlbmVyIjo0LCJ0aW55LWVt
aXR0ZXIiOjd9XX0se30sWzldKSg5KX0pOw==
">
</script>
<style type="text/css">
*{
font-family: Consolas, Serif;
}
body{
margin:0;
padding: 0;
}
h1{
text-align: center;
}
ul{
column-count: 3;
column-gap: 20px;
}
li{
list-style: none;
margin-bottom: 0.2em;
}
.btn{
height : 32px;
background-color: white;
border-radius: 5px;
}
.downloaded{
background-color:yellow;
}
</style>
</head>
<body>
<h1>WWDC 2016 DOWNLOADS</h2>
<ul id="downloadlist">
</ul>
<script type="text/javascript">
var clipboard = new Clipboard('.btn');
</script>
</body>
</html>""")
item = """<li><button class="btn downloaded" data-clipboard-text="{}">{}</button></li>"""
not_downloaded_item = """<li><button class="btn" data-clipboard-text="{}">{}</button></li>"""
entrance = PyQuery(url=url)
videos = entrance('li')
for v in videos:
v = PyQuery(v)
if v.attr("data-released") == "true":
h5 = v.find("h5")
a = v.find("a[href]")
(title, page) = (h5.text(), url + a.attr("href"))
subpage = PyQuery(page)
dl_url = urllib.parse.urlparse(subpage("a:contains('HD')").attr.href).path
print("[{}]({})".format(title, dl_url))
if os.path.exists(os.path.join(savefolder, os.path.basename(urllib.parse.urlsplit(dl_url).path))):
html("#downloadlist").append(item.format("curl {} -O -C -".format(dl_url),title))
else:
html("#downloadlist").append(not_downloaded_item.format("curl {} -O -C -".format(dl_url), title))
with open(os.path.join(savefolder, "downloads.html"), "w+", encoding="utf8") as f:
print(html.outer_html())
f.write(html.outer_html())
subprocess.Popen(["explorer", os.path.join(savefolder, "downloads.html")])
示例6: test_identify_document
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outer_html [as 别名]
def test_identify_document(document, result):
root = PyQuery(document)
identify_document(root)
assert root.outer_html() == result