我需要一些帮助才能创建jquery脚本:)
我的HTML上有一些这样的链接.
<a href="http://google.com">Google</a>
<a href="/">Home</a>
<a href="http://www.gusdecool.com/">Home</a>
<a href="contactus.html">Contact Us</a>
Run Code Online (Sandbox Code Playgroud)
现在我希望jQuery检查我页面上的所有链接.如果该链接在我的服务器之外(我的服务器是gusdecool.com).然后添加target="_blank".结果将是这样的
<a href="http://google.com" target="_blank">Google</a>
<a href="/">Home</a>
<a href="http://www.gusdecool.com/">Home</a>
<a href="contactus.html">Contact Us</a>
Run Code Online (Sandbox Code Playgroud) 使用带有html5lib的beautifulsoup,它会自动放置html,head和body标签:
BeautifulSoup('<h1>FOO</h1>', 'html5lib') # => <html><head></head><body><h1>FOO</h1></body></html>
Run Code Online (Sandbox Code Playgroud)
我可以设置任何选项,关闭此行为?
这个问题特定于BeautifulSoup4,这使得它与以前的问题不同:
BeautifulSoup中的selfClosingTags
既然BeautifulStoneSoup已经消失了(以前的xml解析器),我怎样才能bs4尊重新的自闭标签?例如:
import bs4
S = '''<foo> <bar a="3"/> </foo>'''
soup = bs4.BeautifulSoup(S, selfClosingTags=['bar'])
print soup.prettify()
Run Code Online (Sandbox Code Playgroud)
不会自动关闭bar标签,但会给出提示.bs4所指的这个树构建器是什么以及如何自我关闭标记?
/usr/local/lib/python2.7/dist-packages/bs4/__init__.py:112: UserWarning: BS4 does not respect the selfClosingTags argument to the BeautifulSoup constructor. The tree builder is responsible for understanding self-closing tags.
"BS4 does not respect the selfClosingTags argument to the "
<html>
<body>
<foo>
<bar a="3">
</bar>
</foo>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)