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


Python soupy.Soupy类代码示例

本文整理汇总了Python中soupy.Soupy的典型用法代码示例。如果您正苦于以下问题:Python Soupy类的具体用法?Python Soupy怎么用?Python Soupy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Soupy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_failed_search

    def test_failed_search(self):
        node = Soupy('<a><b>1</b></a><a>2</a>')

        with pytest.raises(NullValueError):
            node.find_all('a').dump(
                a=Q.find('b').text
            )
开发者ID:asd1355215911,项目名称:soupy,代码行数:7,代码来源:test_soupy.py

示例2: test_orelse

    def test_orelse(self):
        node = Soupy('<a><b>1</b></a><a>2</a>')

        result = node.find_all('a').dump(
            a=Q.find('b').text.map(int).orelse(0)
        ).val()

        assert result == [{'a': 1}, {'a': 0}]
开发者ID:asd1355215911,项目名称:soupy,代码行数:8,代码来源:test_soupy.py

示例3: test_multi_dump

    def test_multi_dump(self):
        node = Soupy('<a val="1">1</a><a>2</a><a val="3">3</a>')

        result = node.find_all('a').dump(
            a=Q.text,
            b=Q.attrs.get('val')).val()
        assert result == [{'a': '1', 'b': '1'},
                          {'a': '2', 'b': None},
                          {'a': '3', 'b': '3'}]
开发者ID:asd1355215911,项目名称:soupy,代码行数:9,代码来源:test_soupy.py

示例4: test_navstring_dump

    def test_navstring_dump(self):
        node = Soupy('<div><a>1</a>2<a>3</a></div>')

        result = node.find('div').contents.each(Q.text).val()
        assert result == ['1', '2', '3']

        result = (node.find('div').contents
                  .each(Q.contents[0].text.orelse('!'))
                  .val())
        assert result == ['1', '!', '3']
开发者ID:asd1355215911,项目名称:soupy,代码行数:10,代码来源:test_soupy.py

示例5: test_simple_dump

    def test_simple_dump(self):
        node = Soupy('<a>1</a><a>2</a><a>3</a>')

        result = node.find_all('a').dump(a=Q.text).val()
        assert result == [{'a': '1'}, {'a': '2'}, {'a': '3'}]

        result = node.find_all('a').dump(Q.text).val()
        assert result == [('1',), ('2',), ('3',)]

        with pytest.raises(ValueError):
            node.find('a').dump(Q.text, a=Q.text)
开发者ID:ChrisBeaumont,项目名称:soupy,代码行数:11,代码来源:test_soupy.py

示例6: test_find_multi_methods

 def test_find_multi_methods(self, method):
     node = Soupy("""
         <div>
            <div></div>
            <b><div></div></b>
            <div></div>
        </div>
        """).find('b')
     dom = node.val()
     expected = getattr(dom, method)('div')
     assert expected
     actual = getattr(node, method)('div').val()
     assert actual == expected
开发者ID:asd1355215911,项目名称:soupy,代码行数:13,代码来源:test_soupy.py

示例7: __init__

    def __init__(self, url, generator = correct_content_generator):

        self.url = url
        self.tags = []
        self.img_url = []

        soup = Soupy(download(url))

        self.title = soup.find('title').text.val() or 'Lorem Ipsum'
        self.safe_title = safe_chars(self.title)
        try:
            find_start_tag(soup)
        except NameError as err:
            generator = only_p_generator
        
        for tag in generator(soup):
            self.retrieve_file(tag)
开发者ID:flyingjam,项目名称:epubmaker,代码行数:17,代码来源:pyn.py

示例8: check_podcast

def check_podcast(type, url):
    global CHANNEL, videos, bot, apikey

    page = Soupy(urllib.urlopen(url))
    try:
        namenode = page.find("h2")
        latestname = namenode.text.val()
        if not latestname == videos[type]:
            latestdesc = page.find(class_="deck").text.val().strip()
            bot.say(CHANNEL, "[New %s] %s - %s %s" % (PODCAST_NAMES[type], latestname, latestdesc, url))
            log.info("New %s: %s" % (PODCAST_NAMES[type], latestname))
            videos[type] = latestname
            return True
        return False
    except:
        log.error("Failed checking for latest %s at %s" % (type, url))
        return False
开发者ID:EArmour,项目名称:pyfibot,代码行数:17,代码来源:module_giantbomb.py

示例9: get_chart

 def get_chart(self, chart_name):
     self.chart_list = []
     self.chart_name = chart_name.lower()
     global KeyError
     try:
         number = self.chart_titles_dict[self.chart_name]
     except KeyError:
         #return json.dumps(["That chart does not exist"], indent = 2)
         raise ValueError('That chart does not exist')
     self.url = self.base_url + str(number)
     raw = requests.get(self.url)
     soup = Soupy(raw.text)
     tr_container = soup.find_all('tr',{'class':'latc_song'})
     global NameError
     pos = 0
     song_title_constant = 2
     song_artist_constant = 3
     for table_row in tr_container:
         children = table_row.children
         null_container_holder = type(children[0].find('table').find_all('a'))
         for child in children:
             links = child.find('table').find_all('a')
             if type(links) is not null_container_holder:
                 try:
                     try:
                         pos = pos + 1
                         song_title = links[song_title_constant].contents.first().val().string
                         song_artist = links[song_artist_constant].contents.first().val().string
                         self.chart_list.append((('position',pos),('title',song_title), ('artist',song_artist)))
                     except NullValueError, NameError:
                         print ('\n')
                 except NameError:
                     song_title = links[song_title_constant-1].contents.first().val().string
                     song_artist = links[song_artist_constant-1].contents.first().val().string
                     self.chart_list.append((('position',pos),('title',song_title), ('artist',song_artist)))
     return json.dumps(self.chart_list, indent = 3)
开发者ID:marcusbarbu,项目名称:chartsapisite,代码行数:36,代码来源:ChartScraper.py

示例10: test_node_properties

 def test_node_properties(self, attr):
     node = Soupy('<b><d></d><c>test</c><d></d></b>').find('c')
     dom = node.val()
     assert getattr(node, attr).val() == getattr(dom, attr)
开发者ID:asd1355215911,项目名称:soupy,代码行数:4,代码来源:test_soupy.py

示例11: test_either_fallback

    def test_either_fallback(self):
        node = Soupy('<a><b>1</b></a><a>2</a>')

        assert isinstance(node.apply(either(Q.find('d').text,
                                            Q.find('d').text)),
                          Null)
开发者ID:asd1355215911,项目名称:soupy,代码行数:6,代码来源:test_soupy.py

示例12: test_either

    def test_either(self):
        node = Soupy('<a><b>1</b></a><a>2</a>')

        assert node.apply(either(Q.find('c').text,
                                 Q.find('b').text)).val() == '1'
开发者ID:asd1355215911,项目名称:soupy,代码行数:5,代码来源:test_soupy.py

示例13: return_all_links

def return_all_links(url):    
    soup = Soupy(download(url))
    return [tag for tag in soup.find_all('a') if is_tag_not_anchor(tag)]
开发者ID:flyingjam,项目名称:epubmaker,代码行数:3,代码来源:pyn.py

示例14: test_iter

 def test_iter(self):
     node = Soupy('<a class="test">test</a>')
     for a, b in zip(node, node.val()):
         assert a.val() == b
开发者ID:asd1355215911,项目名称:soupy,代码行数:4,代码来源:test_soupy.py

示例15: test_call

 def test_call(self):
     node = Soupy('<a class="test">test</a>')
     assert node('a').val() == node.val()('a')
开发者ID:asd1355215911,项目名称:soupy,代码行数:3,代码来源:test_soupy.py


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