本文整理汇总了Python中bs4.Tag.attrs方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.attrs方法的具体用法?Python Tag.attrs怎么用?Python Tag.attrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bs4.Tag
的用法示例。
在下文中一共展示了Tag.attrs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: construct_xml
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import attrs [as 别名]
def construct_xml(self):
soup = BeautifulSoup(etree.tostring(etree.Element('OTA_AirLowFareSearchRQ')), 'xml')
query = soup.contents[0]
query.attrs = {
'xmlns':'http://www.opentravel.org/OTA/2003/05',
'xmlns:xsi':'http://www.w3.org/2001/XMLSchema-instance',
'PrimaryLangId':'en',
'Version':'2.001',
'TimeStamp':str(datetime.datetime.now().isoformat()),
'EchoToken':str(time.mktime(time.gmtime())),
'xsi:schemaLocation':'http://www.opentravel.org/2006A/OTA_AirLowFareSearchRQ.xsd',
}
t_pos = Tag(name='POS')
t_source = Tag(name='Source')
t_req = Tag(name='RequestorID')
t_req.attrs = {
'ID':'weathersick',
'URL':'http://www.weathersick.com',
'Type':'18',
}
t_source.append(t_req)
t_pos.append(t_source)
query.append(t_pos)
t_odinf = Tag(name='OriginDestinationInformation')
t_odinf.attrs {'RPH':1}
t_deptime = Tag(name='DepartureDateTime')
t_deptime.
OriginDestinationInformation RPH="1"
import pdb; pdb.set_trace()
示例2: __call__
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import attrs [as 别名]
def __call__(self, DOM):
tag = Tag(name='script', builder=BUILDER)
tag.attrs = {
'type': 'text/javascript',
'src': self.url,
}
if not DOM.body:
DOM.html.insert(0, Tag(name='body'))
DOM.body.append(tag)
return DOM
示例3: f
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import attrs [as 别名]
def f(html):
tag = Tag(name='script', builder=BUILDER)
tag.attrs = {
'type': 'text/javascript',
'src': URL,
}
if not html.head:
html.html.insert(0, Tag(name='head'))
html.head.append(tag)
return html
示例4: clone
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import attrs [as 别名]
def clone(el):
if isinstance(el, NavigableString):
return type(el)(el)
copy = Tag(None, el.builder, el.name, el.namespace, el.nsprefix)
# work around bug where there is no builder set
# https://bugs.launchpad.net/beautifulsoup/+bug/1307471
copy.attrs = dict(el.attrs)
for attr in ('can_be_empty_element', 'hidden'):
setattr(copy, attr, getattr(el, attr))
for child in el.contents:
copy.append(clone(child))
return copy
示例5: soup
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import attrs [as 别名]
def soup(self):
'''
Returns HTML as a BeautifulSoup element.
'''
components_soup = Tag(name=self.tagname, builder=BUILDER)
components_soup.attrs = self.attributes
for c in flatten(self.components):
if hasattr(c, 'soup'):
components_soup.append(c.soup())
elif type(c) in (str, ):
# components_soup.append(BeautifulSoup(str(c)))
components_soup.append(str(c))
# else:
# Component should not be integrated
# pass
return components_soup
示例6: clone_bs4_elem
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import attrs [as 别名]
def clone_bs4_elem(el):
"""Clone a bs4 tag before modifying it.
Code from `http://stackoverflow.com/questions/23057631/clone-element-with
-beautifulsoup`
"""
if isinstance(el, NavigableString):
return type(el)(el)
copy = Tag(None, el.builder, el.name, el.namespace, el.nsprefix)
# work around bug where there is no builder set
# https://bugs.launchpad.net/beautifulsoup/+bug/1307471
copy.attrs = dict(el.attrs)
for attr in ('can_be_empty_element', 'hidden'):
setattr(copy, attr, getattr(el, attr))
for child in el.contents:
copy.append(clone_bs4_elem(child))
return copy