[L ibBdZdZdZdZdZgdZddlmZddlZddl Z ddl Z e jjd kre d d d lmZmZd d lmZd dlmZd dlmZd dlmZd dlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'd dl(m)Z)d dl*m+Z+m,Z,ddl-m.Z.m/Z/mZ0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8ddl9m:Z:m;Z;mZ>m?Z?m@Z@ddlAmBZBmCZCmDZDddlEmFZFmGZGmHZHmIZImJZJGdde&ZKeKZLeKZMGddeKZNeOdk(r-ddl Z eKe jZQeReQjyy)afBeautiful Soup Elixir and Tonic - "The Screen-Scraper's Friend". http://www.crummy.com/software/BeautifulSoup/ Beautiful Soup uses a pluggable XML or HTML parser to parse a (possibly invalid) document into a tree representation. Beautiful Soup provides methods and Pythonic idioms that make it easy to navigate, search, and modify the parse tree. Beautiful Soup works with Python 3.7 and up. It works better if lxml and/or html5lib is installed, but they are not required. For more than you ever wanted to know about Beautiful Soup, see the documentation: http://www.crummy.com/software/BeautifulSoup/bs4/doc/ z*Leonard Richardson (leonardr@segfault.org)z4.14.2z*Copyright (c) 2004-2025 Leonard RichardsonMIT)!AttributeResemblesVariableWarning BeautifulSoupComment DeclarationProcessingInstruction ResultSetCSSScript StylesheetTagTemplateString ElementFilter UnicodeDammitCDataDoctypeFeatureNotFoundParserRejectedMarkup StopParsingrGuessedAtParserWarningMarkupResemblesLocatorWarningUnusualUsageWarningXMLParsedAsHTMLWarning)CounterNzYou are trying to use a Python 3-specific version of Beautiful Soup under Python 2. This will not work. The final version of Beautiful Soup to support Python 2 was 4.9.3.)builder_registry TreeBuilder)HTMLParserTreeBuilder)r)r ) _deprecated)rrDEFAULT_OUTPUT_ENCODINGrrNavigableString PageElementrPYTHON_SPECIFIC_ENCODINGSrr r r r ) Formatter)r SoupStrainer) AnycastrDictIteratorListSequenceSizedOptionalTypeUnion) _Encoding _Encodings_IncomingMarkup_InsertableElement_RawAttributeValue_RawAttributeValues _RawMarkup)rrr)rrrrrceZdZUdZdZeed<ddgZeeed<dZ eed<e e e e e fed <e ed <eed <eeed <eeed <eeed<eeed<eeed<eeed<eeed<eeed<eeed<ee ed<eeed<eeed<eed< dUdedeeeeefd eee e e fd eedeedeed ee e e e e fdefdZdVd Zde eeffd!Zd"e eefddfd#Zeed$d%&dedefd'Z ededefd(Z!ededefd)Z"dWd*Z#dWd+Z$ dXd,ed-eed.eed/ee%d0ee&d1ee&d2eed3e'defd4Z( dYd5ee e)de e)fd6Z* dYd7ed8ee e)de)fd9Z+d:e,dee fd;Z-d:e,dee fd<Z.deefd=Z/d>eddfd?Z0dYd@ee e)ddfdAZ1 dZdBe dCeedDee ddfdEZ2dFeddfdGZ3 d[d,ed.eedHedeefdIZ4 d\d,ed-eed.eed/e%d0ee&d1ee&dJee eefdeefdKZ5dYd,ed.eeddfdLZ6dMeddfdNZ7de8dOdfdPee&dQedRee9efdSee:e dedef fdT Z;xZ tag), call handle_starttag and then handle_endtag. z [document] ROOT_TAG_NAMEhtmlfastDEFAULT_BUILDER_FEATURESz ASCII_SPACESelement_classesbuilderis_xml known_xml parse_onlymarkup current_data currentTagtagStackopen_tag_counterpreserve_whitespace_tag_stackstring_container_stack_most_recent_elementoriginal_encodingdeclared_html_encodingcontains_replacement_charactersNfeatures from_encodingexclude_encodingskwargsc dvrd=tjddvrd=tjddvrd=tjddvrd=tjdd vrd =tjd d td td ttffd } |xs | dd}|+|j rtjd|t d|xs | dd}|r't|trtjdd}|xs t|_ |} |} d} t|tr|} d}nd|bt|tr|g}|t|dk(r |j}tj|} | tddj!|z| } || J| d2i}| s| |j"k(st| tr| |j$vs|r|j&rd}nd}d} t)j*d}|r|j.}|j0}nt(j2}d}|j5d}|r&|j7}|j9dr|dd }|r^t|||j"|!}tjt:j<|zt:d"nrtjd#||_|j&|_|j&|_ t|_!||_"tG|d$r)tItJjL|jO}nt|tPtfstG|d%stSd&|d't|tTr`t|d(krRt|tPrd)|vrd*|vst|tr*d+|vr&d,|vr"|jW|s|jY|tItZ|}g}d-}|j>j]|||.D]Z\|_/|_0|_1|_2|jg|j>ji| |jkd/}n|s5|Dcgc] }t|}}tmd0d1j!|zd|_/d|j>_8y#t,$rYwxYw#tl$r}|jo|Yd}~d}~wwxYwcc}w)3a Constructor. :param markup: A string or a file-like object representing markup to be parsed. :param features: Desirable features of the parser to be used. This may be the name of a specific parser ("lxml", "lxml-xml", "html.parser", or "html5lib") or it may be the type of markup to be used ("html", "html5", "xml"). It's recommended that you name a specific parser, so that Beautiful Soup gives you the same results across platforms and virtual environments. :param builder: A TreeBuilder subclass to instantiate (or instance to use) instead of looking one up based on `features`. You only need to use this if you've implemented a custom TreeBuilder. :param parse_only: A SoupStrainer. Only parts of the document matching the SoupStrainer will be considered. This is useful when parsing part of a document that would otherwise be too large to fit into memory. :param from_encoding: A string indicating the encoding of the document to be parsed. Pass this in if Beautiful Soup is guessing wrongly about the document's encoding. :param exclude_encodings: A list of strings indicating encodings known to be wrong. Pass this in if you don't know the document's encoding but you know Beautiful Soup's guess is wrong. :param element_classes: A dictionary mapping BeautifulSoup classes like Tag and NavigableString, to other classes you'd like to be instantiated instead as the parse tree is built. This is useful for subclassing Tag or NavigableString to modify default behavior. :param kwargs: For backwards compatibility purposes, the constructor accepts certain keyword arguments used in Beautiful Soup 3. None of these arguments do anything in Beautiful Soup 4; they will result in a warning and then be ignored. Apart from this, any keyword arguments passed into the BeautifulSoup constructor are propagated to the TreeBuilder constructor. This makes it possible to configure a TreeBuilder by passing in arguments, not just by saying which one to use. convertEntitieszBS4 does not respect the convertEntities argument to the BeautifulSoup constructor. Entities are always converted to Unicode characters. markupMassagezBS4 does not respect the markupMassage argument to the BeautifulSoup constructor. The tree builder is responsible for any necessary markup massage. smartQuotesTozBS4 does not respect the smartQuotesTo argument to the BeautifulSoup constructor. Smart quotes are always converted to Unicode characters.selfClosingTagszBeautiful Soup 4 does not respect the selfClosingTags argument to the BeautifulSoup constructor. The tree builder is responsible for understanding self-closing tags.isHTMLzBeautiful Soup 4 does not respect the isHTML argument to the BeautifulSoup constructor. Suggest you use features='lxml' for HTML and features='lxml-xml' for XML.old_namenew_namereturncv|vr4tjd|d|dtdj|Sy)NzThe "z<" argument to the BeautifulSoup constructor was renamed to "z" in Beautiful Soup 4.0.0r stacklevel)warningswarnDeprecationWarningpop)rXrYrQs R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/bs4/__init__.pydeprecated_argumentz3BeautifulSoup.__init__..deprecated_argument9s?6!  +' zz(++parseOnlyTheserBNz8The given value for parse_only will exclude everything: rr\ fromEncodingrOzlYou provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.rzjCouldn't find a tree builder with the features you requested: %s. Do you need to install a parser library?,XMLHTMLr__file__)z.pycz.pyo)filename line_numberparser markup_typezKeyword arguments to the BeautifulSoup constructor will be ignored. These would normally be passed into the TreeBuilder constructor, but a TreeBuilder instance was passed in as `builder`.read__len__z'Incoming markup is of an invalid type: z?. Markup must be a string, a bytestring, or an open filehandle.< < F)rPTzThe markup you provided was rejected by the parser. Trying a different parser or a different encoding may help. Original exception(s) from parser: z )9r^r_strr.r'excludes_everything UserWarning isinstancedictr>typelenr<rlookuprjoinNAMEALTERNATE_NAMESr@sys _getframe ValueError f_globalsf_lineno__dict__getlowerendswithrMESSAGEr?rA _namespacesrBhasattrr(ioIOBaserqbytes TypeErrorr-_markup_is_url_markup_resembles_filenamer7prepare_markuprCrKrLrMresetinitialize_soup_feedrappendsoup)selfrCrNr?rBrOrPr>rQrcoriginal_builderoriginal_features builder_classpossible_builder_classrocallerglobalsrmrlfnlvalues rejectionssuccesseother_exceptionss ` rb__init__zBeautifulSoup.__init__s?z  &() MM)  f $' MM4  f $' MM)   &() MM7  v x MM  #  #  V#67G#V  !-- Nzl[  & )< O*  Z4 MM~ !M.8$& #$59 gt $#MG _(C($:3x=A#588%5%<%>"'K"(K  ]]1-F$..G"(//K!llG"#K";;z2"..*C||$45#+CR="!)$/&||$/ F MM.66?.#$  R nn 6$ 66 ""))V,113FFUCL1'&):T9&DCD  &3v;#+=  &4v+=%vBU63'Cv,=$fBT &&v.//7j&)  \\ ( ( M5F)   K  "  '  0 JJL LL ( ( .   $0:;1A; ;&k**-./    u"X( !!!$  a l6t||?U?U -AiL* kkm( "Q &()rdstatec ||_t|jtr|j|_n|jst |_||j_|j |jyN)rr|r?r~rrrr)rrs rb __setstate__zBeautifulSoup.__setstate__ sU dllD )<<>DL12DL    rdz)nothing (private method, will be removed)z4.13.0) replaced_byversioncRt|tr|jdd}|S|}|S)aEnsure `markup` is Unicode so it's safe to send into warnings.warn. warnings.warn had this problem back in 2010 but fortunately not anymore. This has not been used for a long time; I just noticed that fact while working on 4.13.0. zutf-8replace)r|rr)clsrCdecodeds rb_decode_markupzBeautifulSoup._decode_markups1 fe $mmGY7GGrdc,d}ttrtfddDxrdv}n,ttrtfddDxrdv}ny|syt j t jtd zt d y ) zError-handling method to raise a warning if incoming markup looks like a URL. :param markup: A string of markup. :return: Whether or not the markup resembled a URL closely enough to justify issuing a warning. Fc3@K|]}j|ywr startswith.0prefixrCs rb z/BeautifulSoup._markup_is_url..6sR&F%%f-R)shttp:shttps: c3@K|]}j|ywrrrs rbrz/BeautifulSoup._markup_is_url..;sP&F%%f-Pr)zhttp:zhttps: URLwhatrr\T) r|ranyryr^r_r URL_MESSAGEr})rrCproblems ` rbrzBeautifulSoup._markup_is_url*s fe $R.as9su~~c"9rTs?*#&;>$|s//s :)rkrrlrrr\) r|ryencoderrrrfindr^r_rFILENAME_MESSAGEr})rrCmarkup_bfilelike extensionsbytecolon_irs @rbrz(BeautifulSoup._markup_resembles_filenameJs fc "}}V,HH E 9j9 9H D{"  H  H    t $..& ' !  ) : :Tz=R R ) rdc|jj|j%|jj|j|j |j f|j j |jk7rB|j|j %|j j |jk7r@yyyy)zInternal method that parses previously set markup, creating a large number of Tag and NavigableString objects. N) r?rrCfeedendDatarEnamer9popTagrs rbrzBeautifulSoup._feeds  ;; " LL  dkk *  OO 'DOO,@,@DDVDV,V KKM OO 'DOO,@,@DDVDV,V ',V 'rdc2tj|||j|jd|_|jj g|_d|_g|_t|_ g|_ g|_ d|_ |j|y)zWReset this object to a state as though it had never parsed any markup. TN)r rr?r9hiddenrrDrErFrrGrHrIrJpushTagrs rbrzBeautifulSoup.resets{ T4t/A/AB   ' -/*&(#$(! Trdr namespacensprefixattrs sourceline sourceposstringkwattrsc |jjdi|} || j||jj t t } t tt | } | d|j|||| ||} ||| _| S)aDCreate a new Tag associated with this BeautifulSoup object. :param name: The name of the new Tag. :param namespace: The URI of the new Tag's XML namespace, if any. :param prefix: The prefix for the new Tag's XML namespace, if any. :param attrs: A dictionary of this Tag's attribute values; can be used instead of ``kwattrs`` for attributes like 'class' that are reserved words in Python. :param sourceline: The line number where this tag was (purportedly) found in its source document. :param sourcepos: The character position within ``sourceline`` where this tag was (purportedly) found. :param string: String content for the new Tag, if any. :param kwattrs: Keyword arguments for the new Tag's attribute values. N)rrrx) r?attribute_dict_classupdater>rr r(r/r) rrrrrrrrrattr_container tag_classtags rbnew_tagzBeautifulSoup.new_tags6;::EWE    ! !% (((,,S#6 cI.   LL    !    CJ rd base_classc|xst}ttt|jj ||}|j rE|tur=|j jj |j dj|}|S)zFind the class that should be instantiated to hold a given kind of string. This may be a built-in Beautiful Soup class or a custom class passed in to the BeautifulSoup constructor. rk) r"r(r/r>rrIr?string_containersr)rr containers rbstring_containerzBeautifulSoup.string_containers1/   !4#7#7#;#;Iy#Q  & &9+G 66::++B/44iIrdssubclassc4|j|}||S)aCreate a new `NavigableString` associated with this `BeautifulSoup` object. :param s: The string content of the `NavigableString` :param subclass: The subclass of `NavigableString`, if any, to use. If a document is being processed, an appropriate subclass for the current location in the document will be determined automatically. )r)rrrrs rb new_stringzBeautifulSoup.new_strings))(3 |rdargsctd)This method is part of the PageElement API, but `BeautifulSoup` doesn't implement it because there is nothing before or after it in the parse tree. z4BeautifulSoup objects don't support insert_before().NotImplementedErrorrrs rb insert_beforezBeautifulSoup.insert_befores" B  rdctd)rz3BeautifulSoup objects don't support insert_after().rrs rb insert_afterzBeautifulSoup.insert_afters""WXXrdc|jsy|jj}|j|jvr!|j|jxxdzcc<|jr,||jdk(r|jj|j r,||j dk(r|j j|jr|jd|_|j S)zZInternal method called by _popToTag when a tag is closed. :meta private: Nrrk)rFrarrGrHrIrErrs rbrzBeautifulSoup.popTags }}mm! 88t,, ,  ! !#(( +q 0 +  . .t99"==  . . 2 2 4  & &3$2M2Mb2Q+Q  ' ' + + - =="mmB/DOrdrc.|j%|jjj||jj||jd|_|j|j k7r!|j |jxxdz cc<|j|jjvr|jj||j|jjvr|jj|yy)z`Internal method called by handle_starttag when a tag is opened. :meta private: Nrkr) rErrrFrr9rGr?preserve_whitespace_tagsrHrrIrs rbrzBeautifulSoup.pushTag,s ?? & OO $ $ + +C 0 S!--+ 88t)) )  ! !#(( +q 0 + 88t||<< <  . . 5 5c : 88t||55 5  ' ' . .s 3 6rdcontainerClassc|jrdj|j}|js&d}|D]}||jvsd}n|r d|vrd}nd}g|_|jr4t |j dkr|jj|sy|j|}||}|j|yy)zMethod called by the TreeBuilder when the end of a data segment occurs. :param containerClass: The class to use when incorporating the data segment into the parse tree. :meta private: rTFrwrrN) rDrrHr=rBrrFallow_string_creationrobject_was_parsed)rr rD strippableios rbrzBeautifulSoup.endData=s   774#4#45L55! %A 1 11%* |+'+ '* !#D  &!+>>|L!22>BN|,A  " "1 %= rdrparentmost_recent_elementc| |j}|J||}n |j}dx}x}}t|tr2|j}|j }|j }| |j}|jdu}|j|||||||_|jj||r|j|yy)zuMethod called by the TreeBuilder to integrate an object into the parse tree. :meta private: N) rErJr|r next_element next_siblingprevious_siblingprevious_elementsetuprr_linkage_fixer) rrrrrrrrfixs rbrzBeautifulSoup.object_was_parsedfs >__F!!!  *2 #88 9== =', a >>L>>L 11 '#$#5#5 !!- (,8H,W$%!q!     ' rdelc|jd}|jd}|}||ur:|j.||_|j}| ||urd|_||_d|_d|_t |tr+|jrtt|jd}d|_d|_|} |y|j #|j |_||j _y|j}?)z,Make sure linkage of this fragment is sound.rrkNF) rrrrrrr|r r(r#_last_descendant)rrfirstchild descendantprev_eltargets rbrzBeautifulSoup._linkage_fixers A B"' E>bii3#BO,,G"wb'8'+$%'E "%)E "" eS !ennk5+A+A%+HIJ #' "&  "~$$0*0*=*= '7<##4]]Frd inclusivePopc^||jk(ryd}t|j}t|dz ddD]r}|jj |s|S|j|}||j k(r$||jk(r|r|j}|S|j}t|S)aPops the tag stack up to and including the most recent instance of the given tag. If there are no open tags with the given name, nothing will be popped. :param name: Pop up to the most recent tag with this name. :param nsprefix: The namespace prefix that goes with `name`. :param inclusivePop: It this is false, pops the tag stack up to but *not* including the most recent instqance of the given tag. :meta private: Nrrrk) r9rrFrangerGrrrr)rrrr$most_recently_popped stack_sizerts rb _popToTagzBeautifulSoup._popToTags$ 4%% %#' zA~q"- 1A((,,T2$# a Aqvv~(ahh"6+/;;=($#$(;;=  1$#rd namespacesc |j|jr6t|jdkr|jj |||sy|j j tt}ttt|}|||j|||||j|j||| } | | S|j| |j_ | |_ |j| | S)aCalled by the tree builder when a new tag is encountered. :param name: Name of the tag. :param nsprefix: Namespace prefix for the tag. :param attrs: A dictionary of attribute values. Note that attribute values are expected to be simple strings; processing of multi-valued attributes such as "class" comes later. :param sourceline: The line number where this tag was found in its source document. :param sourcepos: The character position within `sourceline` where this tag was found. :param namespaces: A dictionary of all namespace prefix mappings currently in scope in the document. If this method returns None, the tag was rejected by an active `ElementFilter`. You should proceed as if the tag had not occurred in the document. For instance, if this was a self-closing tag, don't call handle_endtag. :meta private: rN)rrr+)rrBrrFallow_tag_creationr>rr r(r/r?rErJrr) rrrrrrrr+rrs rbhandle_starttagzBeautifulSoup.handle_starttags@  OODMM"a'OO66xuM((,,S#6 cI.   LL     OO  % %!!   ;J  $ $ 058D % % 2$'! S rdcH|j|j||y)zCalled by the tree builder when an ending tag is encountered. :param name: Name of the tag. :param nsprefix: Namespace prefix for the tag. :meta private: N)rr*)rrrs rb handle_endtagzBeautifulSoup.handle_endtag s  tX&rddatac:|jj|y)zpCalled by the tree builder when a chunk of textual data is encountered. :meta private: N)rDr)rr1s rb handle_datazBeautifulSoup.handle_data,s   &rdminimal indent_leveleventual_encoding formatteriteratorc |jrd}|}|tvrd}|d|z}d|z}nd}d} d} t|tr|durd}n|durd}d|d } n+|j d d} |rJ| | durd}n| durd}d |d } | rt j | td n |dus| durd}|tt|+||||zS)aMReturns a string representation of the parse tree as a full HTML or XML document. :param indent_level: Each line of the rendering will be indented this many levels. (The ``formatter`` decides what a 'level' means, in terms of spaces or other characters output.) This is used internally in recursive calls while pretty-printing. :param eventual_encoding: The encoding of the final document. If this is None, the document will be a Unicode string. :param formatter: Either a `Formatter` object, or a string naming one of the standard formatters. :param iterator: The iterator to use when navigating over the parse tree. This is only used by `Tag.decode_contents` and you probably won't need to use it. rNz encoding="%s"z TrFzAs of 4.13.0, the first argument to BeautifulSoup.decode has been changed from bool to int, to match Tag.decode. Pass in a value of z instead. pretty_printzAs of 4.13.0, the pretty_print argument to BeautifulSoup.decode has been removed, to match Tag.decode. Pass in a value of indent_level=rpr\) r@r$r|boolrar^r_r`superrr) rr5r6r7r8rQ encoding_partdeclared_encodingrwarningr: __class__s rbrzBeautifulSoup.decode4sC0 ;;M/@  $==%)! , 03D D 0=@FF"&'+ lD )t# &# ]^j]kktuG!::nd;L :'4'#$L!U*#'Ldeqdrr{|  MM'#5! D U "le&;LmT9 +Y   rd)rNNNNNN)rZr)rZN)NNNNNNr)NN)NT)NNN)=__name__ __module__ __qualname____doc__r9ry__annotations__r<r,r=r)r/r#rr;r.r&r7r+r CounterTyper1r3r0r2r'rrrr classmethodr rrrrrr6intr5rr"rrr4rrrrrrrr*r.r0r3r!r%r*r __classcell__r@s@rbrrstB&M3%06v.>hsm>/L#.${+T+->>??  L~&& Z  s) 3i!#&&#'9, I%";// ** %Y// &*)#%8 >?@ Z! \* Z!  * Z!$J/Z!"$tK'8${:K'K"LMZ!Z!x d38n $sCx. T ? J 3  J4>@ @t@@D &$("&/3$(#' $00C=03- 0 +, 0 SM 0C=0 0&0 0f=A"4#89 o 4CG   (o)> ?    #5 ${:K Y"4Yk9JY  .43444"'&htO/D&E'&QU'&X!%59 %( %( %(&k2 %(  %(N*#*#*#ZOS#$#$#+C=#$GK#$ ##$V%)#'/3@@C=@3- @ # @ SM @C=@T#s(^,@ #@D '# '# '$ '''''+'>+448 G smG %G C( G 8K01 G  G  G G rdrc,eZdZdZdedeffd ZxZS)BeautifulStoneSoupz&Deprecated interface to an XML parser.rrQcnd|d<tjdtdtt||i|y)NxmlrNzThe BeautifulStoneSoup class was deprecated in version 4.0.0. Instead of using it, pass features="xml" into the BeautifulSoup constructor.rpr\)r^r_r`r<rLr)rrrQr@s rbrzBeautifulStoneSoup.__init__s<"z  J    $0$A&Ard)rArBrCrDr'rrIrJs@rbrLrLs"0BcBSBBrdrL__main__)TrD __author__ __version__ __copyright__ __license____all__ collectionsrrrr^ version_infomajor ImportErrorr?rrbuilder._htmlparserrdammitrcssr _deprecationr elementrrr!rrr"r#rr$rr r r r r7r%filterrr&typingr'r(rFr)r*r+r,r-r.r/r0 bs4._typingr1r2r3r4r5r6r7bs4.exceptionsrrr bs4._warningsrrrrrr_s_souprLrAstdinrprintprettifyrxrdrbrhs :  <   < A  u 7! !     t Ct p B B z  #D 4==? rd