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


Python PyQuery.outerHtml方法代码示例

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


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

示例1: render

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
 def render(self, edit=False):
     layout = self.current_layout
     rendered = layout.render()
     if not edit:
         widget_markup = """
         <div id="%(wid)s" class="view-widget">
           %(content)s
         </div>
         """
     else:
         widget_markup = """
         <div id="%(wid)s" class="widget">
           <div class="widget-head"><h3>%(title)s</h3></div>
           <div class="widget-content">%(content)s</div>
         </div>
         """
     pq = PyQuery(rendered)
     for column, addwidgets in self.widget_map.items():
         for addwidget in addwidgets:
             try:
                 widget = self[addwidget]
             except KeyError:
                 continue
             widget_info = {'col': column,
                            'wid': addwidget,
                            'title': widget.title,
                            'content': widget.render(),
                            'url': widget.absolute_url()
                           }
             pq('#%s' % column).append(widget_markup % widget_info)
     return pq.outerHtml()
开发者ID:misaelnieto,项目名称:collective.composition,代码行数:33,代码来源:composition.py

示例2: extract

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
    def extract(self):
        self.html = re.sub("<!--.*?-->", "", self.html)
        doc = PyQuery(self.html)
        content_node = doc("div#blog_article_content")

        content = content_node.outerHtml()
        cpl = re.compile('<img.*?src=".*?"', re.I)
        content = re.sub("%", "%%", content)
        content_doc = PyQuery(content)
        content_doc("img").attr("src", "%s")

        item = ContentItem()
        item["title"] = self.title = doc("div.blog_main_left_content").find("h3").text()
        item["author"] = self.author = doc("div#common_person_blogtitle")("div#title01")("a").text()

        item["content"] = self.content = content_doc.outerHtml()

        self.release_time = doc("div.blog_main_time").find("p").text().strip()
        item["release_time"] = self.release_time

        item["source"] = u"凤凰网"
        item["pic_url"] = ""

        item["image_urls"] = [img.get("src") for img in content_node("img")]

        return item
开发者ID:hw20686832,项目名称:iCrawler,代码行数:28,代码来源:hw_ifeng_bk.py

示例3: test_django_templatetag_url_conversion

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
def test_django_templatetag_url_conversion():
    hp = create_htmlproducer()
    pre_html = """<div class="something">
<div class="test"></div>
<a href="{% url 'schema' release_name 'release_package' %}">text</a>
</div>"""
    pq_dom = PyQuery(pre_html)
    post_pq_html = pq_dom.outerHtml()
    repaired_html = hp.repair_django_tags(post_pq_html)
    assert pre_html == repaired_html
开发者ID:birdsarah,项目名称:standard-collaborator,代码行数:12,代码来源:test_standardscache.py

示例4: test_django_templatevar_conversion

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
def test_django_templatevar_conversion():
    hp = create_htmlproducer()
    pre_html = """<div class="something">
<div class="test"></div>
<a href="{{ STATIC_URL }}docson/widget.js">text</a>
</div>"""
    pq_dom = PyQuery(pre_html)
    post_pq_html = pq_dom.outerHtml()
    repaired_html = hp.repair_django_tags(post_pq_html)
    assert pre_html == repaired_html
开发者ID:birdsarah,项目名称:standard-collaborator,代码行数:12,代码来源:test_standardscache.py

示例5: convert_md_to_html

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
 def convert_md_to_html(self, mdcontent, outer_menu_html, inner_menu_html):
     htmlcontent = markdown(mdcontent, extensions=['footnotes', 'sane_lists', 'toc'])
     pq_dom = PyQuery(htmlcontent)
     rendered_menu = self.extract_toc_to_html(pq_dom)
     self.insert_included_json(pq_dom)
     self.insert_included_csv(pq_dom)
     htmlcontent = pq_dom.outerHtml()
     htmlcontent = self.repair_django_tags(htmlcontent)
     rendered_html = render_to_string('main/menu_content.html', {
         'outer_menu': outer_menu_html,
         'inner_menu': inner_menu_html,
         'html_content': htmlcontent,
     })
     return rendered_html, rendered_menu
开发者ID:birdsarah,项目名称:standard-collaborator,代码行数:16,代码来源:standardscache.py

示例6: sanitise

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
	def sanitise(self, text, markdown = True):
		if markdown:
			text = md(text)
		
		dom = PyQuery(text)
		
		for a in dom.find('a[href^="javascript:"]'):
			a = PyQuery(a)
			a.replaceWith(a.text())

		for obj in UNCLEAN_TAGS:
			dom.find(obj).remove()

		for attr in UNCLEAN_ATTRS:
			dom.find('[%s]' % attr).removeAttr(attr)
		
		text = dom.outerHtml()
		if markdown:
			dom = HTML2Text()
			text = dom.handle(text)

		return text
开发者ID:iamsteadman,项目名称:social-comments,代码行数:24,代码来源:__init__.py

示例7: prepare_html

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
def prepare_html(fileobj):
    """ prepares the html for wordpress pages """
    pq=PyQuery("".join(strip_if_not_pre(fileobj))) 
    
    pq("a.headerlink").remove()
    # Do we want title at all?
    if pq("div.section h1"):
      title= pq("div.section h1")[0].text
      pq("div.section h1:first").remove()
    else:
      title=""

    # TODO: insert toc (??)

    out = PyQuery(pq("div.content").outerHtml() )
    # insert after h1 on 4th ine
    # lines = out.split('\n')
    # out = '\n'.join(lines[:4] + [ '[toc]' ] + lines[4:])

    # now various regex
    
    out.append("<p><small>Last update: %s</small></p>"%(
    datetime.datetime.now().strftime("%Y-%m-%d")))
    out=out.outerHtml()
    # replace .html with / and index.html with simple ./
    pattern = '(internal" href=".[^"]*)index\.html"'
    out = re.sub(pattern, '\\1"', out)
    pattern = 'internal" href="index\.html"'
    out = re.sub(pattern, 'href="./"', out)
    pattern = '(internal" href="[^"]*).html"'
    out = re.sub(pattern, '\\1/"', out)
    pattern = '(internal" href="[^"]*).html#([^"]*)"'
    out = re.sub(pattern, '\\1/#\\2"', out)
    pattern = '(internal" href="[^"]*/)index/#([^"]*)"'
    out = re.sub(pattern, '\\1/#\\2"', out)
    
    
    return (out, title)
开发者ID:foebu,项目名称:datawrangling,代码行数:40,代码来源:upload.py

示例8: WeeronlineSource

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
class WeeronlineSource(Source):
  """Weather source class"""

  __d = None
  __date = None
  __day = None
  __url = 'http://www.weeronline.nl/Europa/Nederland/Eindhoven/4058591'


  def __init__(self):
    """Constructor"""


  def get_weather(self, day):
    if day < 0 or day > 13:
      sys.stderr.write('`day` must be an integer between 0 and 13\n')
      return None
    if day > 3:
      sys.stderr.write('`day` >= 4 not yet supported\n')
      return None

    self.__date = datetime.datetime.now() + datetime.timedelta(days=day)
    self.__day = day

    if not self.__d:
      self.__d = PyQuery(url=self.__url)

    data = None
    try:
      data = self.__parse()
    except:
      html = self.__d.outerHtml().encode('ascii', 'replace')
      sys.stderr.write(html)
      sys.stderr.write('\n\n')
      traceback.print_exc()
    return data


  def __parse(self):
    """Parse the HTML page"""
    container = self.__d('.weatherforecast.FiveDays')
    rows = container.find('.row_forecast')
    iconRows = container.find('.row_weathericons')
    ratingRows = container.find('.row_weathernumbers')
    
    index = self.__day + 1

    w = {}

    w['url'] = self.__url
    w['date'] = self.__date.strftime("%Y-%m-%d")
    w['url_timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    w['day'] = self.__day

    icons = iconRows.eq(0).find('td').eq(index).find('div')
    for i in range(3):
      val = icons.eq(i).attr('class')
      w['icon_' + str(i + 1)] = val

    val = rows.eq(0).find('td').eq(index).text()
    val = val.encode('ascii', 'ignore') # strip the °-sign
    w['temperature_minimum'] = self.__numeric(val)

    val = rows.eq(1).find('td').eq(index).text()
    val = val.encode('ascii', 'ignore') # strip the °-sign
    w['temperature_maximum'] = self.__numeric(val)

    val = rows.eq(2).find('td').eq(index).text()
    val = val.rstrip('/') # strip the '/'
    w['wind_force'] = self.__numeric(val)

    val = rows.eq(2).find('td').eq(index).find('.windImageDiv.darkImage > div').attr('class')
    val = val.replace('wind_icon_small_', '').replace('_xs darkImage', '')
    w['wind_direction'] = val

    val = rows.eq(3).find('td').eq(index).text()
    val = val.rstrip('%') # strip the '%'
    w['rain_percentage'] = self.__numeric(val)

    val = rows.eq(4).find('td').eq(index).text()
    val = val.rstrip('m') # strip the 'mm'
    w['rain_amount'] = self.__numeric(val)

    val = ratingRows.eq(0).find('td').eq(index).text()
    w['rating'] = self.__numeric(val)

    return w


  def __numeric(self, x):
    x = x.replace(',', '.')
    if not x:
      return 0
    return float(x) if '.' in x else int(x)
开发者ID:trenneman,项目名称:weatherik,代码行数:96,代码来源:source_weeronline.py

示例9: KNMISource

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import outerHtml [as 别名]
class KNMISource(Source):
  """Weather source class"""

  __baseUrl = 'http://www.knmi.nl/klimatologie/daggegevens/index.cgi?station=370'
  __d = None
  __date = None
  __day = None
  __url = None


  def __init__(self):
    """Constructor"""


  def get_weather(self, day):
    if day >= 0:
      sys.stderr.write('`day` must be an integer and less than 0\n')
      return None

    date = datetime.datetime.now() + datetime.timedelta(days=day)
    url = self.__get_url(date)

    self.__date = date
    self.__day = day
    self.__url = url

    self.__d = PyQuery(url=url)

    data = None
    try:
      data = self.__parse()
    except:
      html = self.__d.outerHtml().encode('ascii', 'replace')
      sys.stderr.write(html)
      sys.stderr.write('\n\n')
      traceback.print_exc()
    return data


  def __parse(self):
    """Parse the HTML page"""
    rows = self.__d('#printable > table > tr')
    
    w = {}

    w['url'] = self.__url
    w['date'] = self.__date.strftime("%Y-%m-%d")
    w['url_timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    w['day'] = self.__day

    w['temperature_average'] = self.__numeric(rows.eq(2).find('td').eq(1).text())
    w['temperature_maximum'] = self.__numeric(rows.eq(3).find('td').eq(1).text())
    w['temperature_minimum'] = self.__numeric(rows.eq(4).find('td').eq(1).text())

    w['rain_amount'] = self.__numeric(rows.eq(2).find('td').eq(6).text().lstrip('<-'))
    w['rain_duration'] = self.__numeric(rows.eq(3).find('td').eq(6).text().lstrip('-'))

    w['sunshine_duration'] = self.__numeric(rows.eq(7).find('td').eq(1).text())
    w['sunshine_relative'] = self.__numeric(rows.eq(8).find('td').eq(1).text())

    w['sky_coverage'] = self.__numeric(rows.eq(9).find('td').eq(1).text())
    w['sky_visibiliy'] = self.__numeric(rows.eq(11).find('td').eq(1).text().lstrip('<'))

    w['wind_speed_average'] = self.__numeric(rows.eq(7).find('td').eq(6).text())
    w['wind_speed_maximum_average'] = self.__numeric(rows.eq(8).find('td').eq(6).text())
    w['wind_speed_maximum'] = self.__numeric(rows.eq(9).find('td').eq(6).text())
    w['wind_direction'] = self.__numeric(rows.eq(11).find('td').eq(6).text())

    w['atmosphere_humidity'] = self.__numeric(rows.eq(14).find('td').eq(1).text())
    w['atmosphere_pressure'] = self.__numeric(rows.eq(14).find('td').eq(6).text())


    return w


  def __get_url(self, date):
    """Get the remote URL for fetching the weather"""

    params = {
      'year': date.year,
      'month': date.month,
      'day': date.day
    }

    url = self.__baseUrl
    for key, value in params.iteritems():
      url += '&' + key + '=' + str(value)

    return url


  def __numeric(self, x):
    x = x.rstrip('-')
    if not x:
      return 0
    return float(x) if '.' in x else int(x)
开发者ID:trenneman,项目名称:weatherik,代码行数:98,代码来源:source_knmi.py


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