Issue
I need to add a new script tag that has query parameters to my html document so I tried this:
jsmanager = self.soup.new_tag("script", src="https://example.com/myscript.js?data=test&alarm=1")
self.soup.select_one("head").append(jsmanager)
The problem is that after the script element is added the url in the src attribute looks like this:
https://example.com/myscript.js?data=test&alarm=1
Is there any way to add src attribute without html-encoding it's value? (The & thing).
Thanks in advance!
Solution
This is not actually a problem - this is valid html. Both jsmanager.get('src')
and jsmanager.attrs['src']
will give the same link as you set, and jsmanager.prettify(formatter=None)
will also show the tag without encoding the ampersand [the '&' character].
If you add to a html
<script src="https://example.com/myscript.js?data=test&alarm=1"></script>
it should behave as intended. In fact, if you render
<a href="https://example.com/myscript.js?data=test&alarm=1"></a>
and right-click on the link and then Copy link address you will be able to paste the link with the original &
instead of &
.
Answered By - Driftr95
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.