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


Python Commons.load_url_string方法代码示例

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


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

示例1: test_load_url_string

# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import load_url_string [as 别名]
 def test_load_url_string(self):
     url1 = "https://httpbin.org/get"
     data1 = Commons.load_url_string(url1)
     data1split = data1.split("\n")
     assert data1split[0] == "{", "First line incorrect."
     assert data1split[1] == "  \"args\": {}, ", "String response incorrect."
     url2 = "https://httpbin.org/headers"
     headers2 = [["User-Agent", "Example data"]]
     data2 = Commons.load_url_string(url2, headers2)
     data2split = data2.split("\n")
     assert data2split[0] == "{", "First line incorrect."
     assert data2split[1] == "  \"headers\": {", "String response incorrect."
     assert "\"User-Agent\": \"Example data\"" in data2, "Headers missing from request."
开发者ID:joshcoales,项目名称:Hallo,代码行数:15,代码来源:testCommons.py

示例2: check_feed

# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import load_url_string [as 别名]
 def check_feed(self):
     """
     Checks the feed for any updates
     :return: list of ElementTree XML elements
     """
     rss_data = Commons.load_url_string(self.url)
     rss_elem = ElementTree.fromstring(rss_data)
     channel_elem = rss_elem.find("channel")
     new_items = []
     # Update title
     title_elem = channel_elem.find("title")
     self.title = title_elem.text
     # Loop elements, seeing when any match the last item's hash
     latest_hash = None
     for item_elem in channel_elem.findall("item"):
         item_xml = ElementTree.tostring(item_elem)
         item_hash = hashlib.md5(item_xml).hexdigest()
         if latest_hash is None:
             latest_hash = item_hash
         if item_hash == self.last_item_hash:
             break
         new_items.append(item_elem)
     # Update last item hash
     self.last_item_hash = latest_hash
     self.last_check = datetime.now()
     # Return new items
     return new_items
开发者ID:,项目名称:,代码行数:29,代码来源:

示例3: run

# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import load_url_string [as 别名]
 def run(self, line, user_obj, destination_obj=None):
     api_key = user_obj.get_server().get_hallo().get_api_key("thecatapi")
     if api_key is None:
         return "No API key loaded for cat api."
     url = "http://thecatapi.com/api/images/get?format=xml&api_key=" + api_key + "&type=gif"
     xml_string = Commons.load_url_string(url)
     doc = minidom.parseString(xml_string)
     cat_url = doc.getElementsByTagName("url")[0].firstChild.data
     return cat_url
开发者ID:,项目名称:,代码行数:11,代码来源:

示例4: get_rss_data

# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import load_url_string [as 别名]
 def get_rss_data(self):
     headers = None
     # Tumblr feeds need "GoogleBot" in the URL, or they'll give a GDPR notice
     if "tumblr.com" in self.url:
         headers = [["User-Agent", "Hallo IRCBot [email protected] (GoogleBot/4.5.1)"]]
     # Actually get the data
     rss_data = Commons.load_url_string(self.url, headers)
     # PHDComics doesn't always escape ampersands correctly
     if "phdcomics" in self.url:
         rss_data = rss_data.replace("& ", "& ")
     # Chainsaw suit has a blank first line
     if "chainsawsuit" in self.url and rss_data.startswith("\r\n"):
         rss_data = rss_data[2:]
     return rss_data
开发者ID:joshcoales,项目名称:Hallo,代码行数:16,代码来源:Subscriptions.py


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