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


Python HTMLParser.lstrip方法代码示例

本文整理汇总了Python中html.parser.HTMLParser.lstrip方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLParser.lstrip方法的具体用法?Python HTMLParser.lstrip怎么用?Python HTMLParser.lstrip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在html.parser.HTMLParser的用法示例。


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

示例1: print_title

# 需要导入模块: from html.parser import HTMLParser [as 别名]
# 或者: from html.parser.HTMLParser import lstrip [as 别名]
def print_title(url, chan, nick, mode, cont):
    try:
        r = requests.get(url, verify=False)
        if r.headers["content-type"].split("/")[0] == "text":
            html_doc = r.text
            r.close()
            title = snarfer(html_doc)
            title = HTMLParser().unescape(title)
            title = title.lstrip()
            chanmodes = cont.get_info("modes")
            
            # Select the channels on which the script will publicly print the title
            # by replacing firstchannel, secondchannel, third channel etc.
            # you can also delete them or add them but you have to maintain the same syntax
            # do not delete quotes ( ' ' )
            if chan == '#firstchannel' or chan == '#secondchannel' or chan == '#thirdchannel':
                # PRINT IN CHANNEL
                # WARNING: In case two or more people in the same channel are using this script,
		# deleting or commenting the line with URL in it is strongly suggested
                # (could lead to endless chain-reactions otherwise)
                #
                # If channel has colors disabled
                if "c" in chanmodes:
                    msg = u":: {0} " + \
                          u":: URL: {1} " + \
                          u"::"     
                # If channel has colors enabled
                else:
                    msg = u"\002::\002\0034 {0} \003" + \
	                  u"\002:: URL: \002\00318\037{1}\017 " + \
                          u"\002::\002"
                msg = msg.format(title, url, nick, mode)
                # Weird context and timing issues with threading, hence:
                cont.command("TIMER 0.1 DOAT {0} MSG {0} {1}".format(chan, msg))
            else:
                # PRINT LOCALLY
                msg = u"\n" + \
                       u"\0033\002::\003 TITLE:\002\0034 {0} \003\n" + \
                       u"\0033\002::\003 URL: \002\00318\037{1}\017\n" + \
                       u"\0033\002::\003 POSTED BY:\002 {3}{2} \017\n" + \
                       u"\n"
                msg = msg.format(title, url, nick, mode)
                # Weird context and timing issues with threading, hence:
                cont.command("TIMER 0.1 DOAT {0} ECHO {1}".format(chan, msg))
    except requests.exceptions.RequestException as e:
        print(e)
开发者ID:anoneemo,项目名称:python-hexchat-scripts,代码行数:48,代码来源:link-title-plus.py


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