当前位置: 首页>>代码示例>>Python>>正文


Python Tag.attrs方法代码示例

本文整理汇总了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()
开发者ID:spiffistan,项目名称:weathersick,代码行数:35,代码来源:test_vayama.py

示例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
开发者ID:oksome,项目名称:Tumulus,代码行数:12,代码来源:__init__.py

示例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
开发者ID:oksome,项目名称:Tumulus,代码行数:12,代码来源:__init__.py

示例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
开发者ID:brannondorsey,项目名称:ofBook,代码行数:15,代码来源:createWebBook.py

示例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
开发者ID:oksome,项目名称:Tumulus,代码行数:18,代码来源:element.py

示例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
开发者ID:haohanchen,项目名称:zhihu-py3,代码行数:20,代码来源:common.py


注:本文中的bs4.Tag.attrs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。