<legend id='A0sDx'><style id='A0sDx'><dir id='A0sDx'><q id='A0sDx'></q></dir></style></legend>
    <i id='A0sDx'><tr id='A0sDx'><dt id='A0sDx'><q id='A0sDx'><span id='A0sDx'><b id='A0sDx'><form id='A0sDx'><ins id='A0sDx'></ins><ul id='A0sDx'></ul><sub id='A0sDx'></sub></form><legend id='A0sDx'></legend><bdo id='A0sDx'><pre id='A0sDx'><center id='A0sDx'></center></pre></bdo></b><th id='A0sDx'></th></span></q></dt></tr></i><div id='A0sDx'><tfoot id='A0sDx'></tfoot><dl id='A0sDx'><fieldset id='A0sDx'></fieldset></dl></div>
      • <bdo id='A0sDx'></bdo><ul id='A0sDx'></ul>

    1. <small id='A0sDx'></small><noframes id='A0sDx'>

        <tfoot id='A0sDx'></tfoot>
      1. 如何找到评论标签&lt;!--...--&gt;美丽汤?

        时间:2023-07-31
          <tbody id='5JIIM'></tbody>

            • <bdo id='5JIIM'></bdo><ul id='5JIIM'></ul>

                <small id='5JIIM'></small><noframes id='5JIIM'>

                  <i id='5JIIM'><tr id='5JIIM'><dt id='5JIIM'><q id='5JIIM'><span id='5JIIM'><b id='5JIIM'><form id='5JIIM'><ins id='5JIIM'></ins><ul id='5JIIM'></ul><sub id='5JIIM'></sub></form><legend id='5JIIM'></legend><bdo id='5JIIM'><pre id='5JIIM'><center id='5JIIM'></center></pre></bdo></b><th id='5JIIM'></th></span></q></dt></tr></i><div id='5JIIM'><tfoot id='5JIIM'></tfoot><dl id='5JIIM'><fieldset id='5JIIM'></fieldset></dl></div>
                • <tfoot id='5JIIM'></tfoot>
                  <legend id='5JIIM'><style id='5JIIM'><dir id='5JIIM'><q id='5JIIM'></q></dir></style></legend>
                  本文介绍了如何找到评论标签&lt;!--...--&gt;美丽汤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试了 soup.find('!--') 但它似乎不起作用.提前致谢.

                  I tried soup.find('!--') but it doesn't seem to work. Thanks in advance.

                  感谢您提供有关如何查找所有评论的提示.我有一个后续问题.我如何专门搜索评论?

                  Thanks for the tip on how to find all comments. I have a follow up question. How do I specifically search out for a comment?

                  例如,我有以下评论标签:

                  For example, I have the following comment tag:

                  <!-- <span class="titlefont"><i>星期三 110518</i>(05:00PM)<br/></span>-->

                  我真的只是想要这些东西 <i>Wednesday 110518</i>.110518"是我倾向于用作搜索目标的日期 YYMMDD.但是,我不知道如何在特定的评论标签中找到一些东西.

                  I really just want this stuff <i>Wednesday 110518</i>. The "110518" is the date YYMMDD which I'm leaning on using as my search target. However, I don't know how to find something within a specific comment tag.

                  推荐答案

                  Pyparsing 允许您使用内置的 htmlComment 表达式搜索 HTML 注释,并附加解析时回调以验证和提取各种评论中的数据字段:

                  Pyparsing allows you to search for HTML comments using a builtin htmlComment expression, and attach parse-time callbacks to validate and extract the various data fields within the comment:

                  from pyparsing import makeHTMLTags, oneOf, withAttribute, Word, nums, Group, htmlComment
                  import calendar
                  
                  # have pyparsing define tag start/end expressions for the 
                  # tags we want to look for inside the comments
                  span,spanEnd = makeHTMLTags("span")
                  i,iEnd = makeHTMLTags("i")
                  
                  # only want spans with class=titlefont
                  span.addParseAction(withAttribute(**{'class':'titlefont'}))
                  
                  # define what specifically we are looking for in this comment
                  weekdayname = oneOf(list(calendar.day_name))
                  integer = Word(nums)
                  dateExpr = Group(weekdayname("day") + integer("daynum"))
                  commentBody = '<!--' + span + i + dateExpr("date") + iEnd
                  
                  # define a parse action to attach to the standard htmlComment expression,
                  # to extract only what we want (or raise a ParseException in case 
                  # this is not one of the comments we're looking for)
                  def grabCommentContents(tokens):
                      return commentBody.parseString(tokens[0])
                  htmlComment.addParseAction(grabCommentContents)
                  
                  
                  # let's try it
                  htmlsource = """
                  want to match this one
                  <!-- <span class="titlefont"> <i>Wednesday 110518</i>(05:00PM)<br /></span> -->
                  
                  don't want the next one, wrong span class
                  <!-- <span class="bodyfont"> <i>Wednesday 110519</i>(05:00PM)<br /></span> -->
                  
                  not even a span tag!
                  <!-- some other text with a date in italics <i>Wednesday 110520</i>(05:00PM)<br /></span> -->
                  
                  another matching comment, on a different day
                  <!-- <span class="titlefont"> <i>Thursday 110521</i>(05:00PM)<br /></span> -->
                  """
                  
                  for comment in htmlComment.searchString(htmlsource):
                      parsedDate = comment.date
                      # date info can be accessed like elements in a list
                      print parsedDate[0], parsedDate[1]
                      # because we named the expressions within the dateExpr Group
                      # we can also get at them by name (this is much more robust, and 
                      # easier to maintain/update later)
                      print parsedDate.day
                      print parsedDate.daynum
                      print
                  

                  打印:

                  Wednesday 110518
                  Wednesday
                  110518
                  
                  Thursday 110521
                  Thursday
                  110521
                  

                  这篇关于如何找到评论标签&lt;!--...--&gt;美丽汤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将输入标签中的两个数字相加? 下一篇:如何取消加载图像

                  相关文章

                    <bdo id='BFBeq'></bdo><ul id='BFBeq'></ul>
                  <i id='BFBeq'><tr id='BFBeq'><dt id='BFBeq'><q id='BFBeq'><span id='BFBeq'><b id='BFBeq'><form id='BFBeq'><ins id='BFBeq'></ins><ul id='BFBeq'></ul><sub id='BFBeq'></sub></form><legend id='BFBeq'></legend><bdo id='BFBeq'><pre id='BFBeq'><center id='BFBeq'></center></pre></bdo></b><th id='BFBeq'></th></span></q></dt></tr></i><div id='BFBeq'><tfoot id='BFBeq'></tfoot><dl id='BFBeq'><fieldset id='BFBeq'></fieldset></dl></div>
                    <legend id='BFBeq'><style id='BFBeq'><dir id='BFBeq'><q id='BFBeq'></q></dir></style></legend>

                    1. <tfoot id='BFBeq'></tfoot>
                    2. <small id='BFBeq'></small><noframes id='BFBeq'>