相关疑难解决方法(0)

jQuery为传出链接添加target ="_ blank"

我需要一些帮助才能创建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)

javascript jquery

31
推荐指数
4
解决办法
7万
查看次数

不要自动放置html,head和body标签,beautifulsoup

使用带有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)

我可以设置任何选项,关闭此行为?

python beautifulsoup html5lib

29
推荐指数
3
解决办法
8379
查看次数

如何让BeautifulSoup 4尊重自动关闭标签?

这个问题特定于BeautifulSoup4,这使得它与以前的问题不同:

为什么BeautifulSoup会修改我的自闭元素?

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)

python xml beautifulsoup xml-parsing

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

标签 统计

beautifulsoup ×2

python ×2

html5lib ×1

javascript ×1

jquery ×1

xml ×1

xml-parsing ×1