如何使用pyquery修改python中的节点属性
我想使用 pyquery 来做到这一点。
例如:
html='<div>arya stark<img src="1111"/>ahahah<img src="2222"/></div>'
a=PyQuery(html)
我想将 html 修改为
<div>arya stark<img src="aaaa"/>ahahah<img src="bbbb"/></div>
, 只需要更改img元素的src属性,并获取修改后的html。
有什么想法吗?或者有其他方法吗?
谢谢
iwant use pyquery to do this.
for example:
html='<div>arya stark<img src="1111"/>ahahah<img src="2222"/></div>'
a=PyQuery(html)
i want to modify the html to
<div>arya stark<img src="aaaa"/>ahahah<img src="bbbb"/></div>
in other words,
just need change img element's src attribute, and get the modified html.
any ideas?or any other method?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 PyQuery 意味着您镜像 jQuery,也许 这个问题 是相关的。长话短说,使用
attr()
方法:Since PyQuery is meant you mirror jQuery, perhaps this question would be relevant. Long story short, use the
attr()
method:类似的内容:
要将函数应用于选择,您可以使用 .each(),但请注意,裸元素已传递给该函数:
Something like this:
To apply a function to a selection you can use .each(), but note that bare elements are passed to the function: