diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cafc1c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv/ \ No newline at end of file diff --git a/.venv/Lib/site-packages/__pycache__/typing_extensions.cpython-312.pyc b/.venv/Lib/site-packages/__pycache__/typing_extensions.cpython-312.pyc deleted file mode 100644 index cc08b47..0000000 Binary files a/.venv/Lib/site-packages/__pycache__/typing_extensions.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/INSTALLER b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/METADATA b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/METADATA deleted file mode 100644 index eddfd55..0000000 --- a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/METADATA +++ /dev/null @@ -1,123 +0,0 @@ -Metadata-Version: 2.4 -Name: beautifulsoup4 -Version: 4.13.4 -Summary: Screen-scraping library -Project-URL: Download, https://www.crummy.com/software/BeautifulSoup/bs4/download/ -Project-URL: Homepage, https://www.crummy.com/software/BeautifulSoup/bs4/ -Author-email: Leonard Richardson -License: MIT License -License-File: AUTHORS -License-File: LICENSE -Keywords: HTML,XML,parse,soup -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: MIT License -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 3 -Classifier: Topic :: Software Development :: Libraries :: Python Modules -Classifier: Topic :: Text Processing :: Markup :: HTML -Classifier: Topic :: Text Processing :: Markup :: SGML -Classifier: Topic :: Text Processing :: Markup :: XML -Requires-Python: >=3.7.0 -Requires-Dist: soupsieve>1.2 -Requires-Dist: typing-extensions>=4.0.0 -Provides-Extra: cchardet -Requires-Dist: cchardet; extra == 'cchardet' -Provides-Extra: chardet -Requires-Dist: chardet; extra == 'chardet' -Provides-Extra: charset-normalizer -Requires-Dist: charset-normalizer; extra == 'charset-normalizer' -Provides-Extra: html5lib -Requires-Dist: html5lib; extra == 'html5lib' -Provides-Extra: lxml -Requires-Dist: lxml; extra == 'lxml' -Description-Content-Type: text/markdown - -Beautiful Soup is a library that makes it easy to scrape information -from web pages. It sits atop an HTML or XML parser, providing Pythonic -idioms for iterating, searching, and modifying the parse tree. - -# Quick start - -``` ->>> from bs4 import BeautifulSoup ->>> soup = BeautifulSoup("

SomebadHTML") ->>> print(soup.prettify()) - - -

- Some - - bad - - HTML - - -

- - ->>> soup.find(string="bad") -'bad' ->>> soup.i -HTML -# ->>> soup = BeautifulSoup("SomebadXML", "xml") -# ->>> print(soup.prettify()) - - - Some - - bad - - XML - - -``` - -To go beyond the basics, [comprehensive documentation is available](https://www.crummy.com/software/BeautifulSoup/bs4/doc/). - -# Links - -* [Homepage](https://www.crummy.com/software/BeautifulSoup/bs4/) -* [Documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) -* [Discussion group](https://groups.google.com/group/beautifulsoup/) -* [Development](https://code.launchpad.net/beautifulsoup/) -* [Bug tracker](https://bugs.launchpad.net/beautifulsoup/) -* [Complete changelog](https://git.launchpad.net/beautifulsoup/tree/CHANGELOG) - -# Note on Python 2 sunsetting - -Beautiful Soup's support for Python 2 was discontinued on December 31, -2020: one year after the sunset date for Python 2 itself. From this -point onward, new Beautiful Soup development will exclusively target -Python 3. The final release of Beautiful Soup 4 to support Python 2 -was 4.9.3. - -# Supporting the project - -If you use Beautiful Soup as part of your professional work, please consider a -[Tidelift subscription](https://tidelift.com/subscription/pkg/pypi-beautifulsoup4?utm_source=pypi-beautifulsoup4&utm_medium=referral&utm_campaign=readme). -This will support many of the free software projects your organization -depends on, not just Beautiful Soup. - -If you use Beautiful Soup for personal projects, the best way to say -thank you is to read -[Tool Safety](https://www.crummy.com/software/BeautifulSoup/zine/), a zine I -wrote about what Beautiful Soup has taught me about software -development. - -# Building the documentation - -The bs4/doc/ directory contains full documentation in Sphinx -format. Run `make html` in that directory to create HTML -documentation. - -# Running the unit tests - -Beautiful Soup supports unit test discovery using Pytest: - -``` -$ pytest -``` - diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/RECORD b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/RECORD deleted file mode 100644 index ccf512f..0000000 --- a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/RECORD +++ /dev/null @@ -1,90 +0,0 @@ -beautifulsoup4-4.13.4.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -beautifulsoup4-4.13.4.dist-info/METADATA,sha256=zXwPMgMEIdymEV_lAL0QzP34i6osem_P2nfqgaEexRo,3809 -beautifulsoup4-4.13.4.dist-info/RECORD,, -beautifulsoup4-4.13.4.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -beautifulsoup4-4.13.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87 -beautifulsoup4-4.13.4.dist-info/licenses/AUTHORS,sha256=uYkjiRjh_aweRnF8tAW2PpJJeickE68NmJwd9siry28,2201 -beautifulsoup4-4.13.4.dist-info/licenses/LICENSE,sha256=VbTY1LHlvIbRDvrJG3TIe8t3UmsPW57a-LnNKtxzl7I,1441 -bs4/__init__.py,sha256=ZkHAdXHt3PEkwDrx_Z4ABuz-T_-TSO8aL6Vpy9uiI8M,44212 -bs4/__pycache__/__init__.cpython-312.pyc,, -bs4/__pycache__/_deprecation.cpython-312.pyc,, -bs4/__pycache__/_typing.cpython-312.pyc,, -bs4/__pycache__/_warnings.cpython-312.pyc,, -bs4/__pycache__/css.cpython-312.pyc,, -bs4/__pycache__/dammit.cpython-312.pyc,, -bs4/__pycache__/diagnose.cpython-312.pyc,, -bs4/__pycache__/element.cpython-312.pyc,, -bs4/__pycache__/exceptions.cpython-312.pyc,, -bs4/__pycache__/filter.cpython-312.pyc,, -bs4/__pycache__/formatter.cpython-312.pyc,, -bs4/_deprecation.py,sha256=ucZjfBAUF1B0f5ldNIIhlkHsYjHtvwELWlE3_pAR6Vs,2394 -bs4/_typing.py,sha256=3FgPPPrdsTa-kvn1R36o1k_2SfilcUWm4M9i7G4qFl8,7118 -bs4/_warnings.py,sha256=ZuOETgcnEbZgw2N0nnNXn6wvtrn2ut7AF0d98bvkMFc,4711 -bs4/builder/__init__.py,sha256=TYAKmGFuVfTsI53reHijcZKETnPuvse57KZ6LsZsJRo,31130 -bs4/builder/__pycache__/__init__.cpython-312.pyc,, -bs4/builder/__pycache__/_html5lib.cpython-312.pyc,, -bs4/builder/__pycache__/_htmlparser.cpython-312.pyc,, -bs4/builder/__pycache__/_lxml.cpython-312.pyc,, -bs4/builder/_html5lib.py,sha256=3MXq29SYg9XoS9gu2hgTDU02IQkv8kIBx3rW1QWY3fg,22846 -bs4/builder/_htmlparser.py,sha256=cu9PFkxkqVIIe9nU3fVy-JJhINEhY8cGbsuCwZCnQCA,17872 -bs4/builder/_lxml.py,sha256=9L5pJ7ekI-G3HhOhoxcpjZPqDMRfUoWj4Nnku6B2uR8,18545 -bs4/css.py,sha256=XGQq7HQUDyYEbDorFMGIGek7QGPiFuZYnvNEQ59GyxM,12685 -bs4/dammit.py,sha256=oHd1elJ44kMobBGSQRuG7Wln6M-BLz1unOuUscaL9h0,51472 -bs4/diagnose.py,sha256=zy7_GPQHsTtNf8s10WWIRcC5xH5_8LKs295Aa7iFUyI,7832 -bs4/element.py,sha256=7w9cLT9oTU8lrWm9nnlPqHpa_v4U8UuyIUsWnTHYLbw,109768 -bs4/exceptions.py,sha256=Q9FOadNe8QRvzDMaKSXe2Wtl8JK_oAZW7mbFZBVP_GE,951 -bs4/filter.py,sha256=8lzv5yE0mw7jhYwPyDiFCfXAB4-wDiIgn7m8fmIKcGA,29031 -bs4/formatter.py,sha256=5O4gBxTTi5TLU6TdqsgYI9Io0Gc_6-oCAWpfHI3Thn0,10464 -bs4/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -bs4/tests/__init__.py,sha256=ieOudaXvOWA_g4Gb25adCnhEabtEpRwf9_DdplXKdXQ,52671 -bs4/tests/__pycache__/__init__.cpython-312.pyc,, -bs4/tests/__pycache__/test_builder.cpython-312.pyc,, -bs4/tests/__pycache__/test_builder_registry.cpython-312.pyc,, -bs4/tests/__pycache__/test_css.cpython-312.pyc,, -bs4/tests/__pycache__/test_dammit.cpython-312.pyc,, -bs4/tests/__pycache__/test_element.cpython-312.pyc,, -bs4/tests/__pycache__/test_filter.cpython-312.pyc,, -bs4/tests/__pycache__/test_formatter.cpython-312.pyc,, -bs4/tests/__pycache__/test_fuzz.cpython-312.pyc,, -bs4/tests/__pycache__/test_html5lib.cpython-312.pyc,, -bs4/tests/__pycache__/test_htmlparser.cpython-312.pyc,, -bs4/tests/__pycache__/test_lxml.cpython-312.pyc,, -bs4/tests/__pycache__/test_navigablestring.cpython-312.pyc,, -bs4/tests/__pycache__/test_pageelement.cpython-312.pyc,, -bs4/tests/__pycache__/test_soup.cpython-312.pyc,, -bs4/tests/__pycache__/test_tag.cpython-312.pyc,, -bs4/tests/__pycache__/test_tree.cpython-312.pyc,, -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-4670634698080256.testcase,sha256=yUdXkbpNK7LVOQ0LBHMoqZ1rWaBfSXWytoO_xdSm7Ho,15 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-4818336571064320.testcase,sha256=Uv_dx4a43TSfoNkjU-jHW2nSXkqHFg4XdAw7SWVObUk,23 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-4999465949331456.testcase,sha256=OEyVA0Ej4FxswOElrUNt0In4s4YhrmtaxE_NHGZvGtg,30 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5000587759190016.testcase,sha256=G4vpNBOz-RwMpi6ewEgNEa13zX0sXhmL7VHOyIcdKVQ,15347 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5167584867909632.testcase,sha256=3d8z65o4p7Rur-RmCHoOjzqaYQ8EAtjmiBYTHNyAdl4,19469 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5270998950477824.testcase,sha256=NfGIlit1k40Ip3mlnBkYOkIDJX6gHtjlErwl7gsBjAQ,12 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5375146639360000.testcase,sha256=xy4i1U0nhFHcnyc5pRKS6JRMvuoCNUur-Scor6UxIGw,4317 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5492400320282624.testcase,sha256=Q-UTYpQBUsWoMgIUspUlzveSI-41s4ABC3jajRb-K0o,11502 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5703933063462912.testcase,sha256=2bq3S8KxZgk8EajLReHD8m4_0Lj_nrkyJAxB_z_U0D0,5 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5843991618256896.testcase,sha256=MZDu31LPLfgu6jP9IZkrlwNes3f_sL8WFP5BChkUKdY,35 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5984173902397440.testcase,sha256=w58r-s6besG5JwPXpnz37W2YTj9-_qxFbk6hiEnKeIQ,51495 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6124268085182464.testcase,sha256=q8rkdMECEXKcqVhOf5zWHkSBTQeOPt0JiLg2TZiPCuk,10380 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6241471367348224.testcase,sha256=QfzoOxKwNuqG-4xIrea6MOQLXhfAAOQJ0r9u-J6kSNs,19 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6306874195312640.testcase,sha256=MJ2pHFuuCQUiQz1Kor2sof7LWeRERQ6QK43YNqQHg9o,47 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6450958476902400.testcase,sha256=EItOpSdeD4ewK-qgJ9vtxennwn_huguzXgctrUT7fqE,3546 -bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6600557255327744.testcase,sha256=a2aJTG4FceGSJXsjtxoS8S4jk_8rZsS3aznLkeO2_dY,124 -bs4/tests/fuzz/crash-0d306a50c8ed8bcd0785b67000fcd5dea1d33f08.testcase,sha256=jRFRtCKlP3-3EDLc_iVRTcE6JNymv0rYcVM6qRaPrxI,2607 -bs4/tests/fuzz/crash-ffbdfa8a2b26f13537b68d3794b0478a4090ee4a.testcase,sha256=7NsdCiXWAhNkmoW1pvF7rbZExyLAQIWtDtSHXIsH6YU,103 -bs4/tests/test_builder.py,sha256=BBMBirb4mb-fVdJj4dxQCxrdcjQeulKSKBFrPFVpVOk,1095 -bs4/tests/test_builder_registry.py,sha256=tpJ5Niva_cF49SdzIb1gMo0W4Tiodr8BYSOE3O6P_g8,5064 -bs4/tests/test_css.py,sha256=T_HCMzpe6hTr8d2YFXm0DScr8gT8d6h0MYlhZfo6A4U,18625 -bs4/tests/test_dammit.py,sha256=TQCVe6kKVYSuYjwTtIvIaOYYmWYPMnR_3PK45kimLg4,17840 -bs4/tests/test_element.py,sha256=u7FbTtKE6pYJetD1PgS3fCU1-QQXfB7GaLwfI3s4ROY,4373 -bs4/tests/test_filter.py,sha256=JzvU3eI4r1QyNIHKqhxbZ-M7q5qgw-S7Y73MGI2tNr4,27395 -bs4/tests/test_formatter.py,sha256=a6TaeNOVeg_ZYseiP7atmFyYJkQJqlk-jlVxMlyJC2o,6943 -bs4/tests/test_fuzz.py,sha256=zyaoWgCt8hnRkXecBYM9x91fI_Ao9eQUcsBi76ooJ08,7123 -bs4/tests/test_html5lib.py,sha256=ljMOAds__k9zhfT4jVnxxhZkLEggaT7wqDexzDNwus4,9206 -bs4/tests/test_htmlparser.py,sha256=iDHEI69GcisNP48BeHdLAWlqPGhrBwxftnUM8_3nsR4,6662 -bs4/tests/test_lxml.py,sha256=4fZIsNVbm2zdRQFNNwD-lqwf_QtUtiU4QbtLXISQZBw,7453 -bs4/tests/test_navigablestring.py,sha256=5-vs86ujXcs6LjT1lPYQHLi2ag3eBtFfnrOrjzV665M,5599 -bs4/tests/test_pageelement.py,sha256=lAw-sVP3zJX0VdHXXN1Ia3tci5dgK10Gac5o9G46IIk,16195 -bs4/tests/test_soup.py,sha256=I-mhNheo2-PTvfJToDI43EO4RmGlpKJsYOS19YoQ7-8,22669 -bs4/tests/test_tag.py,sha256=ue32hxQs_a1cMuzyu7MNjK42t0IOGMA6POPLIArMOts,9690 -bs4/tests/test_tree.py,sha256=Iw2e2spk19PEtCObE0ymgJH4n4F5_KbMvpcOeblHBsI,55074 diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/REQUESTED b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/REQUESTED deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/WHEEL b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/WHEEL deleted file mode 100644 index 12228d4..0000000 --- a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/WHEEL +++ /dev/null @@ -1,4 +0,0 @@ -Wheel-Version: 1.0 -Generator: hatchling 1.27.0 -Root-Is-Purelib: true -Tag: py3-none-any diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/licenses/AUTHORS b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/licenses/AUTHORS deleted file mode 100644 index 18926c2..0000000 --- a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/licenses/AUTHORS +++ /dev/null @@ -1,49 +0,0 @@ -Behold, mortal, the origins of Beautiful Soup... -================================================ - -Leonard Richardson is the primary maintainer. - -Aaron DeVore, Isaac Muse and Chris Papademetrious have made -significant contributions to the code base. - -Mark Pilgrim provided the encoding detection code that forms the base -of UnicodeDammit. - -Thomas Kluyver and Ezio Melotti finished the work of getting Beautiful -Soup 4 working under Python 3. - -Simon Willison wrote soupselect, which was used to make Beautiful Soup -support CSS selectors. Isaac Muse wrote SoupSieve, which made it -possible to _remove_ the CSS selector code from Beautiful Soup. - -Sam Ruby helped with a lot of edge cases. - -Jonathan Ellis was awarded the prestigious Beau Potage D'Or for his -work in solving the nestable tags conundrum. - -An incomplete list of people have contributed patches to Beautiful -Soup: - - Istvan Albert, Andrew Lin, Anthony Baxter, Oliver Beattie, Andrew -Boyko, Tony Chang, Francisco Canas, "Delong", Zephyr Fang, Fuzzy, -Roman Gaufman, Yoni Gilad, Richie Hindle, Toshihiro Kamiya, Peteris -Krumins, Kent Johnson, Marek Kapolka, Andreas Kostyrka, Roel Kramer, -Ben Last, Robert Leftwich, Stefaan Lippens, "liquider", Staffan -Malmgren, Ksenia Marasanova, JP Moins, Adam Monsen, John Nagle, "Jon", -Ed Oskiewicz, Martijn Peters, Greg Phillips, Giles Radford, Stefano -Revera, Arthur Rudolph, Marko Samastur, James Salter, Jouni Seppänen, -Alexander Schmolck, Tim Shirley, Geoffrey Sneddon, Ville Skyttä, -"Vikas", Jens Svalgaard, Andy Theyers, Eric Weiser, Glyn Webster, John -Wiseman, Paul Wright, Danny Yoo - -An incomplete list of people who made suggestions or found bugs or -found ways to break Beautiful Soup: - - Hanno Böck, Matteo Bertini, Chris Curvey, Simon Cusack, Bruce Eckel, - Matt Ernst, Michael Foord, Tom Harris, Bill de hOra, Donald Howes, - Matt Patterson, Scott Roberts, Steve Strassmann, Mike Williams, - warchild at redho dot com, Sami Kuisma, Carlos Rocha, Bob Hutchison, - Joren Mc, Michal Migurski, John Kleven, Tim Heaney, Tripp Lilley, Ed - Summers, Dennis Sutch, Chris Smith, Aaron Swartz, Stuart - Turner, Greg Edwards, Kevin J Kalupson, Nikos Kouremenos, Artur de - Sousa Rocha, Yichun Wei, Per Vognsen diff --git a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/licenses/LICENSE b/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/licenses/LICENSE deleted file mode 100644 index 08e3a9c..0000000 --- a/.venv/Lib/site-packages/beautifulsoup4-4.13.4.dist-info/licenses/LICENSE +++ /dev/null @@ -1,31 +0,0 @@ -Beautiful Soup is made available under the MIT license: - - Copyright (c) Leonard Richardson - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - -Beautiful Soup incorporates code from the html5lib library, which is -also made available under the MIT license. Copyright (c) James Graham -and other contributors - -Beautiful Soup has an optional dependency on the soupsieve library, -which is also made available under the MIT license. Copyright (c) -Isaac Muse diff --git a/.venv/Lib/site-packages/bs4/__init__.py b/.venv/Lib/site-packages/bs4/__init__.py deleted file mode 100644 index 324fcfa..0000000 --- a/.venv/Lib/site-packages/bs4/__init__.py +++ /dev/null @@ -1,1170 +0,0 @@ -"""Beautiful 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/ -""" - -__author__ = "Leonard Richardson (leonardr@segfault.org)" -__version__ = "4.13.4" -__copyright__ = "Copyright (c) 2004-2025 Leonard Richardson" -# Use of this source code is governed by the MIT license. -__license__ = "MIT" - -__all__ = [ - "AttributeResemblesVariableWarning", - "BeautifulSoup", - "Comment", - "Declaration", - "ProcessingInstruction", - "ResultSet", - "CSS", - "Script", - "Stylesheet", - "Tag", - "TemplateString", - "ElementFilter", - "UnicodeDammit", - "CData", - "Doctype", - - # Exceptions - "FeatureNotFound", - "ParserRejectedMarkup", - "StopParsing", - - # Warnings - "AttributeResemblesVariableWarning", - "GuessedAtParserWarning", - "MarkupResemblesLocatorWarning", - "UnusualUsageWarning", - "XMLParsedAsHTMLWarning", -] - -from collections import Counter -import sys -import warnings - -# The very first thing we do is give a useful error if someone is -# running this code under Python 2. -if sys.version_info.major < 3: - raise ImportError( - "You 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." - ) - -from .builder import ( - builder_registry, - TreeBuilder, -) -from .builder._htmlparser import HTMLParserTreeBuilder -from .dammit import UnicodeDammit -from .css import CSS -from ._deprecation import ( - _deprecated, -) -from .element import ( - CData, - Comment, - DEFAULT_OUTPUT_ENCODING, - Declaration, - Doctype, - NavigableString, - PageElement, - ProcessingInstruction, - PYTHON_SPECIFIC_ENCODINGS, - ResultSet, - Script, - Stylesheet, - Tag, - TemplateString, -) -from .formatter import Formatter -from .filter import ( - ElementFilter, - SoupStrainer, -) -from typing import ( - Any, - cast, - Counter as CounterType, - Dict, - Iterator, - List, - Sequence, - Optional, - Type, - Union, -) - -from bs4._typing import ( - _Encoding, - _Encodings, - _IncomingMarkup, - _InsertableElement, - _RawAttributeValue, - _RawAttributeValues, - _RawMarkup, -) - -# Import all warnings and exceptions into the main package. -from bs4.exceptions import ( - FeatureNotFound, - ParserRejectedMarkup, - StopParsing, -) -from bs4._warnings import ( - AttributeResemblesVariableWarning, - GuessedAtParserWarning, - MarkupResemblesLocatorWarning, - UnusualUsageWarning, - XMLParsedAsHTMLWarning, -) - - -class BeautifulSoup(Tag): - """A data structure representing a parsed HTML or XML document. - - Most of the methods you'll call on a BeautifulSoup object are inherited from - PageElement or Tag. - - Internally, this class defines the basic interface called by the - tree builders when converting an HTML/XML document into a data - structure. The interface abstracts away the differences between - parsers. To write a new tree builder, you'll need to understand - these methods as a whole. - - These methods will be called by the BeautifulSoup constructor: - * reset() - * feed(markup) - - The tree builder may call these methods from its feed() implementation: - * handle_starttag(name, attrs) # See note about return value - * handle_endtag(name) - * handle_data(data) # Appends to the current data node - * endData(containerClass) # Ends the current data node - - No matter how complicated the underlying parser is, you should be - able to build a tree using 'start tag' events, 'end tag' events, - 'data' events, and "done with data" events. - - If you encounter an empty-element tag (aka a self-closing tag, - like HTML's
tag), call handle_starttag and then - handle_endtag. - """ - - #: Since `BeautifulSoup` subclasses `Tag`, it's possible to treat it as - #: a `Tag` with a `Tag.name`. Hoever, this name makes it clear the - #: `BeautifulSoup` object isn't a real markup tag. - ROOT_TAG_NAME: str = "[document]" - - #: If the end-user gives no indication which tree builder they - #: want, look for one with these features. - DEFAULT_BUILDER_FEATURES: Sequence[str] = ["html", "fast"] - - #: A string containing all ASCII whitespace characters, used in - #: during parsing to detect data chunks that seem 'empty'. - ASCII_SPACES: str = "\x20\x0a\x09\x0c\x0d" - - # FUTURE PYTHON: - element_classes: Dict[Type[PageElement], Type[PageElement]] #: :meta private: - builder: TreeBuilder #: :meta private: - is_xml: bool - known_xml: Optional[bool] - parse_only: Optional[SoupStrainer] #: :meta private: - - # These members are only used while parsing markup. - markup: Optional[_RawMarkup] #: :meta private: - current_data: List[str] #: :meta private: - currentTag: Optional[Tag] #: :meta private: - tagStack: List[Tag] #: :meta private: - open_tag_counter: CounterType[str] #: :meta private: - preserve_whitespace_tag_stack: List[Tag] #: :meta private: - string_container_stack: List[Tag] #: :meta private: - _most_recent_element: Optional[PageElement] #: :meta private: - - #: Beautiful Soup's best guess as to the character encoding of the - #: original document. - original_encoding: Optional[_Encoding] - - #: The character encoding, if any, that was explicitly defined - #: in the original document. This may or may not match - #: `BeautifulSoup.original_encoding`. - declared_html_encoding: Optional[_Encoding] - - #: This is True if the markup that was parsed contains - #: U+FFFD REPLACEMENT_CHARACTER characters which were not present - #: in the original markup. These mark character sequences that - #: could not be represented in Unicode. - contains_replacement_characters: bool - - def __init__( - self, - markup: _IncomingMarkup = "", - features: Optional[Union[str, Sequence[str]]] = None, - builder: Optional[Union[TreeBuilder, Type[TreeBuilder]]] = None, - parse_only: Optional[SoupStrainer] = None, - from_encoding: Optional[_Encoding] = None, - exclude_encodings: Optional[_Encodings] = None, - element_classes: Optional[Dict[Type[PageElement], Type[PageElement]]] = None, - **kwargs: Any, - ): - """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. - """ - if "convertEntities" in kwargs: - del kwargs["convertEntities"] - warnings.warn( - "BS4 does not respect the convertEntities argument to the " - "BeautifulSoup constructor. Entities are always converted " - "to Unicode characters." - ) - - if "markupMassage" in kwargs: - del kwargs["markupMassage"] - warnings.warn( - "BS4 does not respect the markupMassage argument to the " - "BeautifulSoup constructor. The tree builder is responsible " - "for any necessary markup massage." - ) - - if "smartQuotesTo" in kwargs: - del kwargs["smartQuotesTo"] - warnings.warn( - "BS4 does not respect the smartQuotesTo argument to the " - "BeautifulSoup constructor. Smart quotes are always converted " - "to Unicode characters." - ) - - if "selfClosingTags" in kwargs: - del kwargs["selfClosingTags"] - warnings.warn( - "Beautiful Soup 4 does not respect the selfClosingTags argument to the " - "BeautifulSoup constructor. The tree builder is responsible " - "for understanding self-closing tags." - ) - - if "isHTML" in kwargs: - del kwargs["isHTML"] - warnings.warn( - "Beautiful 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." - ) - - def deprecated_argument(old_name: str, new_name: str) -> Optional[Any]: - if old_name in kwargs: - warnings.warn( - 'The "%s" argument to the BeautifulSoup constructor ' - 'was renamed to "%s" in Beautiful Soup 4.0.0' - % (old_name, new_name), - DeprecationWarning, - stacklevel=3, - ) - return kwargs.pop(old_name) - return None - - parse_only = parse_only or deprecated_argument("parseOnlyThese", "parse_only") - if parse_only is not None: - # Issue a warning if we can tell in advance that - # parse_only will exclude the entire tree. - if parse_only.excludes_everything: - warnings.warn( - f"The given value for parse_only will exclude everything: {parse_only}", - UserWarning, - stacklevel=3, - ) - - from_encoding = from_encoding or deprecated_argument( - "fromEncoding", "from_encoding" - ) - - if from_encoding and isinstance(markup, str): - warnings.warn( - "You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored." - ) - from_encoding = None - - self.element_classes = element_classes or dict() - - # We need this information to track whether or not the builder - # was specified well enough that we can omit the 'you need to - # specify a parser' warning. - original_builder = builder - original_features = features - - builder_class: Type[TreeBuilder] - if isinstance(builder, type): - # A builder class was passed in; it needs to be instantiated. - builder_class = builder - builder = None - elif builder is None: - if isinstance(features, str): - features = [features] - if features is None or len(features) == 0: - features = self.DEFAULT_BUILDER_FEATURES - possible_builder_class = builder_registry.lookup(*features) - if possible_builder_class is None: - raise FeatureNotFound( - "Couldn't find a tree builder with the features you " - "requested: %s. Do you need to install a parser library?" - % ",".join(features) - ) - builder_class = possible_builder_class - - # At this point either we have a TreeBuilder instance in - # builder, or we have a builder_class that we can instantiate - # with the remaining **kwargs. - if builder is None: - builder = builder_class(**kwargs) - if ( - not original_builder - and not ( - original_features == builder.NAME - or ( - isinstance(original_features, str) - and original_features in builder.ALTERNATE_NAMES - ) - ) - and markup - ): - # The user did not tell us which TreeBuilder to use, - # and we had to guess. Issue a warning. - if builder.is_xml: - markup_type = "XML" - else: - markup_type = "HTML" - - # This code adapted from warnings.py so that we get the same line - # of code as our warnings.warn() call gets, even if the answer is wrong - # (as it may be in a multithreading situation). - caller = None - try: - caller = sys._getframe(1) - except ValueError: - pass - if caller: - globals = caller.f_globals - line_number = caller.f_lineno - else: - globals = sys.__dict__ - line_number = 1 - filename = globals.get("__file__") - if filename: - fnl = filename.lower() - if fnl.endswith((".pyc", ".pyo")): - filename = filename[:-1] - if filename: - # If there is no filename at all, the user is most likely in a REPL, - # and the warning is not necessary. - values = dict( - filename=filename, - line_number=line_number, - parser=builder.NAME, - markup_type=markup_type, - ) - warnings.warn( - GuessedAtParserWarning.MESSAGE % values, - GuessedAtParserWarning, - stacklevel=2, - ) - else: - if kwargs: - warnings.warn( - "Keyword 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`." - ) - - self.builder = builder - self.is_xml = builder.is_xml - self.known_xml = self.is_xml - self._namespaces = dict() - self.parse_only = parse_only - - if hasattr(markup, "read"): # It's a file-type object. - markup = markup.read() - elif not isinstance(markup, (bytes, str)) and not hasattr(markup, "__len__"): - raise TypeError( - f"Incoming markup is of an invalid type: {markup!r}. Markup must be a string, a bytestring, or an open filehandle." - ) - elif len(markup) <= 256 and ( - (isinstance(markup, bytes) and b"<" not in markup and b"\n" not in markup) - or (isinstance(markup, str) and "<" not in markup and "\n" not in markup) - ): - # Issue warnings for a couple beginner problems - # involving passing non-markup to Beautiful Soup. - # Beautiful Soup will still parse the input as markup, - # since that is sometimes the intended behavior. - if not self._markup_is_url(markup): - self._markup_resembles_filename(markup) - - # At this point we know markup is a string or bytestring. If - # it was a file-type object, we've read from it. - markup = cast(_RawMarkup, markup) - - rejections = [] - success = False - for ( - self.markup, - self.original_encoding, - self.declared_html_encoding, - self.contains_replacement_characters, - ) in self.builder.prepare_markup( - markup, from_encoding, exclude_encodings=exclude_encodings - ): - self.reset() - self.builder.initialize_soup(self) - try: - self._feed() - success = True - break - except ParserRejectedMarkup as e: - rejections.append(e) - pass - - if not success: - other_exceptions = [str(e) for e in rejections] - raise ParserRejectedMarkup( - "The markup you provided was rejected by the parser. Trying a different parser or a different encoding may help.\n\nOriginal exception(s) from parser:\n " - + "\n ".join(other_exceptions) - ) - - # Clear out the markup and remove the builder's circular - # reference to this object. - self.markup = None - self.builder.soup = None - - def copy_self(self) -> "BeautifulSoup": - """Create a new BeautifulSoup object with the same TreeBuilder, - but not associated with any markup. - - This is the first step of the deepcopy process. - """ - clone = type(self)("", None, self.builder) - - # Keep track of the encoding of the original document, - # since we won't be parsing it again. - clone.original_encoding = self.original_encoding - return clone - - def __getstate__(self) -> Dict[str, Any]: - # Frequently a tree builder can't be pickled. - d = dict(self.__dict__) - if "builder" in d and d["builder"] is not None and not self.builder.picklable: - d["builder"] = type(self.builder) - # Store the contents as a Unicode string. - d["contents"] = [] - d["markup"] = self.decode() - - # If _most_recent_element is present, it's a Tag object left - # over from initial parse. It might not be picklable and we - # don't need it. - if "_most_recent_element" in d: - del d["_most_recent_element"] - return d - - def __setstate__(self, state: Dict[str, Any]) -> None: - # If necessary, restore the TreeBuilder by looking it up. - self.__dict__ = state - if isinstance(self.builder, type): - self.builder = self.builder() - elif not self.builder: - # We don't know which builder was used to build this - # parse tree, so use a default we know is always available. - self.builder = HTMLParserTreeBuilder() - self.builder.soup = self - self.reset() - self._feed() - - @classmethod - @_deprecated( - replaced_by="nothing (private method, will be removed)", version="4.13.0" - ) - def _decode_markup(cls, markup: _RawMarkup) -> str: - """Ensure `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. - """ - if isinstance(markup, bytes): - decoded = markup.decode("utf-8", "replace") - else: - decoded = markup - return decoded - - @classmethod - def _markup_is_url(cls, markup: _RawMarkup) -> bool: - """Error-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. - """ - problem: bool = False - if isinstance(markup, bytes): - problem = ( - any(markup.startswith(prefix) for prefix in (b"http:", b"https:")) - and b" " not in markup - ) - elif isinstance(markup, str): - problem = ( - any(markup.startswith(prefix) for prefix in ("http:", "https:")) - and " " not in markup - ) - else: - return False - - if not problem: - return False - warnings.warn( - MarkupResemblesLocatorWarning.URL_MESSAGE % dict(what="URL"), - MarkupResemblesLocatorWarning, - stacklevel=3, - ) - return True - - @classmethod - def _markup_resembles_filename(cls, markup: _RawMarkup) -> bool: - """Error-handling method to issue a warning if incoming markup - resembles a filename. - - :param markup: A string of markup. - :return: Whether or not the markup resembled a filename - closely enough to justify issuing a warning. - """ - markup_b: bytes - - # We're only checking ASCII characters, so rather than write - # the same tests twice, convert Unicode to a bytestring and - # operate on the bytestring. - if isinstance(markup, str): - markup_b = markup.encode("utf8") - else: - markup_b = markup - - # Step 1: does it end with a common textual file extension? - filelike = False - lower = markup_b.lower() - extensions = [b".html", b".htm", b".xml", b".xhtml", b".txt"] - if any(lower.endswith(ext) for ext in extensions): - filelike = True - if not filelike: - return False - - # Step 2: it _might_ be a file, but there are a few things - # we can look for that aren't very common in filenames. - - # Characters that have special meaning to Unix shells. (< was - # excluded before this method was called.) - # - # Many of these are also reserved characters that cannot - # appear in Windows filenames. - for byte in markup_b: - if byte in b"?*#&;>$|": - return False - - # Two consecutive forward slashes (as seen in a URL) or two - # consecutive spaces (as seen in fixed-width data). - # - # (Paths to Windows network shares contain consecutive - # backslashes, so checking that doesn't seem as helpful.) - if b"//" in markup_b: - return False - if b" " in markup_b: - return False - - # A colon in any position other than position 1 (e.g. after a - # Windows drive letter). - if markup_b.startswith(b":"): - return False - colon_i = markup_b.rfind(b":") - if colon_i not in (-1, 1): - return False - - # Step 3: If it survived all of those checks, it's similar - # enough to a file to justify issuing a warning. - warnings.warn( - MarkupResemblesLocatorWarning.FILENAME_MESSAGE % dict(what="filename"), - MarkupResemblesLocatorWarning, - stacklevel=3, - ) - return True - - def _feed(self) -> None: - """Internal method that parses previously set markup, creating a large - number of Tag and NavigableString objects. - """ - # Convert the document to Unicode. - self.builder.reset() - - if self.markup is not None: - self.builder.feed(self.markup) - # Close out any unfinished strings and close all the open tags. - self.endData() - while ( - self.currentTag is not None and self.currentTag.name != self.ROOT_TAG_NAME - ): - self.popTag() - - def reset(self) -> None: - """Reset this object to a state as though it had never parsed any - markup. - """ - Tag.__init__(self, self, self.builder, self.ROOT_TAG_NAME) - self.hidden = True - self.builder.reset() - self.current_data = [] - self.currentTag = None - self.tagStack = [] - self.open_tag_counter = Counter() - self.preserve_whitespace_tag_stack = [] - self.string_container_stack = [] - self._most_recent_element = None - self.pushTag(self) - - def new_tag( - self, - name: str, - namespace: Optional[str] = None, - nsprefix: Optional[str] = None, - attrs: Optional[_RawAttributeValues] = None, - sourceline: Optional[int] = None, - sourcepos: Optional[int] = None, - string: Optional[str] = None, - **kwattrs: _RawAttributeValue, - ) -> Tag: - """Create 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. - - """ - attr_container = self.builder.attribute_dict_class(**kwattrs) - if attrs is not None: - attr_container.update(attrs) - tag_class = self.element_classes.get(Tag, Tag) - - # Assume that this is either Tag or a subclass of Tag. If not, - # the user brought type-unsafety upon themselves. - tag_class = cast(Type[Tag], tag_class) - tag = tag_class( - None, - self.builder, - name, - namespace, - nsprefix, - attr_container, - sourceline=sourceline, - sourcepos=sourcepos, - ) - - if string is not None: - tag.string = string - return tag - - def string_container( - self, base_class: Optional[Type[NavigableString]] = None - ) -> Type[NavigableString]: - """Find 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. - """ - container = base_class or NavigableString - - # The user may want us to use some other class (hopefully a - # custom subclass) instead of the one we'd use normally. - container = cast( - Type[NavigableString], self.element_classes.get(container, container) - ) - - # On top of that, we may be inside a tag that needs a special - # container class. - if self.string_container_stack and container is NavigableString: - container = self.builder.string_containers.get( - self.string_container_stack[-1].name, container - ) - return container - - def new_string( - self, s: str, subclass: Optional[Type[NavigableString]] = None - ) -> NavigableString: - """Create 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. - """ - container = self.string_container(subclass) - return container(s) - - def insert_before(self, *args: _InsertableElement) -> List[PageElement]: - """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. - """ - raise NotImplementedError( - "BeautifulSoup objects don't support insert_before()." - ) - - def insert_after(self, *args: _InsertableElement) -> List[PageElement]: - """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. - """ - raise NotImplementedError("BeautifulSoup objects don't support insert_after().") - - def popTag(self) -> Optional[Tag]: - """Internal method called by _popToTag when a tag is closed. - - :meta private: - """ - if not self.tagStack: - # Nothing to pop. This shouldn't happen. - return None - tag = self.tagStack.pop() - if tag.name in self.open_tag_counter: - self.open_tag_counter[tag.name] -= 1 - if ( - self.preserve_whitespace_tag_stack - and tag == self.preserve_whitespace_tag_stack[-1] - ): - self.preserve_whitespace_tag_stack.pop() - if self.string_container_stack and tag == self.string_container_stack[-1]: - self.string_container_stack.pop() - # print("Pop", tag.name) - if self.tagStack: - self.currentTag = self.tagStack[-1] - return self.currentTag - - def pushTag(self, tag: Tag) -> None: - """Internal method called by handle_starttag when a tag is opened. - - :meta private: - """ - # print("Push", tag.name) - if self.currentTag is not None: - self.currentTag.contents.append(tag) - self.tagStack.append(tag) - self.currentTag = self.tagStack[-1] - if tag.name != self.ROOT_TAG_NAME: - self.open_tag_counter[tag.name] += 1 - if tag.name in self.builder.preserve_whitespace_tags: - self.preserve_whitespace_tag_stack.append(tag) - if tag.name in self.builder.string_containers: - self.string_container_stack.append(tag) - - def endData(self, containerClass: Optional[Type[NavigableString]] = None) -> None: - """Method 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: - """ - if self.current_data: - current_data = "".join(self.current_data) - # If whitespace is not preserved, and this string contains - # nothing but ASCII spaces, replace it with a single space - # or newline. - if not self.preserve_whitespace_tag_stack: - strippable = True - for i in current_data: - if i not in self.ASCII_SPACES: - strippable = False - break - if strippable: - if "\n" in current_data: - current_data = "\n" - else: - current_data = " " - - # Reset the data collector. - self.current_data = [] - - # Should we add this string to the tree at all? - if ( - self.parse_only - and len(self.tagStack) <= 1 - and (not self.parse_only.allow_string_creation(current_data)) - ): - return - - containerClass = self.string_container(containerClass) - o = containerClass(current_data) - self.object_was_parsed(o) - - def object_was_parsed( - self, - o: PageElement, - parent: Optional[Tag] = None, - most_recent_element: Optional[PageElement] = None, - ) -> None: - """Method called by the TreeBuilder to integrate an object into the - parse tree. - - :meta private: - """ - if parent is None: - parent = self.currentTag - assert parent is not None - previous_element: Optional[PageElement] - if most_recent_element is not None: - previous_element = most_recent_element - else: - previous_element = self._most_recent_element - - next_element = previous_sibling = next_sibling = None - if isinstance(o, Tag): - next_element = o.next_element - next_sibling = o.next_sibling - previous_sibling = o.previous_sibling - if previous_element is None: - previous_element = o.previous_element - - fix = parent.next_element is not None - - o.setup(parent, previous_element, next_element, previous_sibling, next_sibling) - - self._most_recent_element = o - parent.contents.append(o) - - # Check if we are inserting into an already parsed node. - if fix: - self._linkage_fixer(parent) - - def _linkage_fixer(self, el: Tag) -> None: - """Make sure linkage of this fragment is sound.""" - - first = el.contents[0] - child = el.contents[-1] - descendant: PageElement = child - - if child is first and el.parent is not None: - # Parent should be linked to first child - el.next_element = child - # We are no longer linked to whatever this element is - prev_el = child.previous_element - if prev_el is not None and prev_el is not el: - prev_el.next_element = None - # First child should be linked to the parent, and no previous siblings. - child.previous_element = el - child.previous_sibling = None - - # We have no sibling as we've been appended as the last. - child.next_sibling = None - - # This index is a tag, dig deeper for a "last descendant" - if isinstance(child, Tag) and child.contents: - # _last_decendant is typed as returning Optional[PageElement], - # but the value can't be None here, because el is a Tag - # which we know has contents. - descendant = cast(PageElement, child._last_descendant(False)) - - # As the final step, link last descendant. It should be linked - # to the parent's next sibling (if found), else walk up the chain - # and find a parent with a sibling. It should have no next sibling. - descendant.next_element = None - descendant.next_sibling = None - - target: Optional[Tag] = el - while True: - if target is None: - break - elif target.next_sibling is not None: - descendant.next_element = target.next_sibling - target.next_sibling.previous_element = child - break - target = target.parent - - def _popToTag( - self, name: str, nsprefix: Optional[str] = None, inclusivePop: bool = True - ) -> Optional[Tag]: - """Pops 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: - """ - # print("Popping to %s" % name) - if name == self.ROOT_TAG_NAME: - # The BeautifulSoup object itself can never be popped. - return None - - most_recently_popped = None - - stack_size = len(self.tagStack) - for i in range(stack_size - 1, 0, -1): - if not self.open_tag_counter.get(name): - break - t = self.tagStack[i] - if name == t.name and nsprefix == t.prefix: - if inclusivePop: - most_recently_popped = self.popTag() - break - most_recently_popped = self.popTag() - - return most_recently_popped - - def handle_starttag( - self, - name: str, - namespace: Optional[str], - nsprefix: Optional[str], - attrs: _RawAttributeValues, - sourceline: Optional[int] = None, - sourcepos: Optional[int] = None, - namespaces: Optional[Dict[str, str]] = None, - ) -> Optional[Tag]: - """Called 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: - """ - # print("Start tag %s: %s" % (name, attrs)) - self.endData() - - if ( - self.parse_only - and len(self.tagStack) <= 1 - and not self.parse_only.allow_tag_creation(nsprefix, name, attrs) - ): - return None - - tag_class = self.element_classes.get(Tag, Tag) - # Assume that this is either Tag or a subclass of Tag. If not, - # the user brought type-unsafety upon themselves. - tag_class = cast(Type[Tag], tag_class) - tag = tag_class( - self, - self.builder, - name, - namespace, - nsprefix, - attrs, - self.currentTag, - self._most_recent_element, - sourceline=sourceline, - sourcepos=sourcepos, - namespaces=namespaces, - ) - if tag is None: - return tag - if self._most_recent_element is not None: - self._most_recent_element.next_element = tag - self._most_recent_element = tag - self.pushTag(tag) - return tag - - def handle_endtag(self, name: str, nsprefix: Optional[str] = None) -> None: - """Called 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: - """ - # print("End tag: " + name) - self.endData() - self._popToTag(name, nsprefix) - - def handle_data(self, data: str) -> None: - """Called by the tree builder when a chunk of textual data is - encountered. - - :meta private: - """ - self.current_data.append(data) - - def decode( - self, - indent_level: Optional[int] = None, - eventual_encoding: _Encoding = DEFAULT_OUTPUT_ENCODING, - formatter: Union[Formatter, str] = "minimal", - iterator: Optional[Iterator[PageElement]] = None, - **kwargs: Any, - ) -> str: - """Returns 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. - """ - if self.is_xml: - # Print the XML declaration - encoding_part = "" - declared_encoding: Optional[str] = eventual_encoding - if eventual_encoding in PYTHON_SPECIFIC_ENCODINGS: - # This is a special Python encoding; it can't actually - # go into an XML document because it means nothing - # outside of Python. - declared_encoding = None - if declared_encoding is not None: - encoding_part = ' encoding="%s"' % declared_encoding - prefix = '\n' % encoding_part - else: - prefix = "" - - # Prior to 4.13.0, the first argument to this method was a - # bool called pretty_print, which gave the method a different - # signature from its superclass implementation, Tag.decode. - # - # The signatures of the two methods now match, but just in - # case someone is still passing a boolean in as the first - # argument to this method (or a keyword argument with the old - # name), we can handle it and put out a DeprecationWarning. - warning: Optional[str] = None - if isinstance(indent_level, bool): - if indent_level is True: - indent_level = 0 - elif indent_level is False: - indent_level = None - warning = f"As 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 {indent_level} instead." - else: - pretty_print = kwargs.pop("pretty_print", None) - assert not kwargs - if pretty_print is not None: - if pretty_print is True: - indent_level = 0 - elif pretty_print is False: - indent_level = None - warning = f"As 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={indent_level} instead." - - if warning: - warnings.warn(warning, DeprecationWarning, stacklevel=2) - elif indent_level is False or pretty_print is False: - indent_level = None - return prefix + super(BeautifulSoup, self).decode( - indent_level, eventual_encoding, formatter, iterator - ) - - -# Aliases to make it easier to get started quickly, e.g. 'from bs4 import _soup' -_s = BeautifulSoup -_soup = BeautifulSoup - - -class BeautifulStoneSoup(BeautifulSoup): - """Deprecated interface to an XML parser.""" - - def __init__(self, *args: Any, **kwargs: Any): - kwargs["features"] = "xml" - warnings.warn( - "The BeautifulStoneSoup class was deprecated in version 4.0.0. Instead of using " - 'it, pass features="xml" into the BeautifulSoup constructor.', - DeprecationWarning, - stacklevel=2, - ) - super(BeautifulStoneSoup, self).__init__(*args, **kwargs) - - -# If this file is run as a script, act as an HTML pretty-printer. -if __name__ == "__main__": - import sys - - soup = BeautifulSoup(sys.stdin) - print((soup.prettify())) diff --git a/.venv/Lib/site-packages/bs4/__pycache__/__init__.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index d92a275..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/_deprecation.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/_deprecation.cpython-312.pyc deleted file mode 100644 index 6010cc4..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/_deprecation.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/_typing.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/_typing.cpython-312.pyc deleted file mode 100644 index 7589fac..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/_typing.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/_warnings.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/_warnings.cpython-312.pyc deleted file mode 100644 index 3988abf..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/_warnings.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/css.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/css.cpython-312.pyc deleted file mode 100644 index 2f6c21c..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/css.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/dammit.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/dammit.cpython-312.pyc deleted file mode 100644 index e1f1168..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/dammit.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/diagnose.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/diagnose.cpython-312.pyc deleted file mode 100644 index c2ae749..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/diagnose.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/element.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/element.cpython-312.pyc deleted file mode 100644 index 3737cf6..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/element.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/exceptions.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/exceptions.cpython-312.pyc deleted file mode 100644 index 01a8750..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/exceptions.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/filter.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/filter.cpython-312.pyc deleted file mode 100644 index a50b668..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/filter.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/__pycache__/formatter.cpython-312.pyc b/.venv/Lib/site-packages/bs4/__pycache__/formatter.cpython-312.pyc deleted file mode 100644 index a785cbb..0000000 Binary files a/.venv/Lib/site-packages/bs4/__pycache__/formatter.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/_deprecation.py b/.venv/Lib/site-packages/bs4/_deprecation.py deleted file mode 100644 index a0d7fdc..0000000 --- a/.venv/Lib/site-packages/bs4/_deprecation.py +++ /dev/null @@ -1,80 +0,0 @@ -"""Helper functions for deprecation. - -This interface is itself unstable and may change without warning. Do -not use these functions yourself, even as a joke. The underscores are -there for a reason. No support will be given. - -In particular, most of this will go away without warning once -Beautiful Soup drops support for Python 3.11, since Python 3.12 -defines a `@typing.deprecated() -decorator. `_ -""" - -import functools -import warnings - -from typing import ( - Any, - Callable, -) - - -def _deprecated_alias(old_name: str, new_name: str, version: str): - """Alias one attribute name to another for backward compatibility - - :meta private: - """ - - @property - def alias(self) -> Any: - ":meta private:" - warnings.warn( - f"Access to deprecated property {old_name}. (Replaced by {new_name}) -- Deprecated since version {version}.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(self, new_name) - - @alias.setter - def alias(self, value: str) -> None: - ":meta private:" - warnings.warn( - f"Write to deprecated property {old_name}. (Replaced by {new_name}) -- Deprecated since version {version}.", - DeprecationWarning, - stacklevel=2, - ) - return setattr(self, new_name, value) - - return alias - - -def _deprecated_function_alias( - old_name: str, new_name: str, version: str -) -> Callable[[Any], Any]: - def alias(self, *args: Any, **kwargs: Any) -> Any: - ":meta private:" - warnings.warn( - f"Call to deprecated method {old_name}. (Replaced by {new_name}) -- Deprecated since version {version}.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(self, new_name)(*args, **kwargs) - - return alias - - -def _deprecated(replaced_by: str, version: str) -> Callable: - def deprecate(func: Callable) -> Callable: - @functools.wraps(func) - def with_warning(*args: Any, **kwargs: Any) -> Any: - ":meta private:" - warnings.warn( - f"Call to deprecated method {func.__name__}. (Replaced by {replaced_by}) -- Deprecated since version {version}.", - DeprecationWarning, - stacklevel=2, - ) - return func(*args, **kwargs) - - return with_warning - - return deprecate diff --git a/.venv/Lib/site-packages/bs4/_typing.py b/.venv/Lib/site-packages/bs4/_typing.py deleted file mode 100644 index ac4ec34..0000000 --- a/.venv/Lib/site-packages/bs4/_typing.py +++ /dev/null @@ -1,196 +0,0 @@ -# Custom type aliases used throughout Beautiful Soup to improve readability. - -# Notes on improvements to the type system in newer versions of Python -# that can be used once Beautiful Soup drops support for older -# versions: -# -# * ClassVar can be put on class variables now. -# * In 3.10, x|y is an accepted shorthand for Union[x,y]. -# * In 3.10, TypeAlias gains capabilities that can be used to -# improve the tree matching types (I don't remember what, exactly). -# * In 3.9 it's possible to specialize the re.Match type, -# e.g. re.Match[str]. In 3.8 there's a typing.re namespace for this, -# but it's removed in 3.12, so to support the widest possible set of -# versions I'm not using it. - -from typing_extensions import ( - runtime_checkable, - Protocol, - TypeAlias, -) -from typing import ( - Any, - Callable, - Dict, - IO, - Iterable, - Mapping, - Optional, - Pattern, - TYPE_CHECKING, - Union, -) - -if TYPE_CHECKING: - from bs4.element import ( - AttributeValueList, - NamespacedAttribute, - NavigableString, - PageElement, - ResultSet, - Tag, - ) - - -@runtime_checkable -class _RegularExpressionProtocol(Protocol): - """A protocol object which can accept either Python's built-in - `re.Pattern` objects, or the similar ``Regex`` objects defined by the - third-party ``regex`` package. - """ - - def search( - self, string: str, pos: int = ..., endpos: int = ... - ) -> Optional[Any]: ... - - @property - def pattern(self) -> str: ... - - -# Aliases for markup in various stages of processing. -# -#: The rawest form of markup: either a string, bytestring, or an open filehandle. -_IncomingMarkup: TypeAlias = Union[str, bytes, IO[str], IO[bytes]] - -#: Markup that is in memory but has (potentially) yet to be converted -#: to Unicode. -_RawMarkup: TypeAlias = Union[str, bytes] - -# Aliases for character encodings -# - -#: A data encoding. -_Encoding: TypeAlias = str - -#: One or more data encodings. -_Encodings: TypeAlias = Iterable[_Encoding] - -# Aliases for XML namespaces -# - -#: The prefix for an XML namespace. -_NamespacePrefix: TypeAlias = str - -#: The URL of an XML namespace -_NamespaceURL: TypeAlias = str - -#: A mapping of prefixes to namespace URLs. -_NamespaceMapping: TypeAlias = Dict[_NamespacePrefix, _NamespaceURL] - -#: A mapping of namespace URLs to prefixes -_InvertedNamespaceMapping: TypeAlias = Dict[_NamespaceURL, _NamespacePrefix] - -# Aliases for the attribute values associated with HTML/XML tags. -# - -#: The value associated with an HTML or XML attribute. This is the -#: relatively unprocessed value Beautiful Soup expects to come from a -#: `TreeBuilder`. -_RawAttributeValue: TypeAlias = str - -#: A dictionary of names to `_RawAttributeValue` objects. This is how -#: Beautiful Soup expects a `TreeBuilder` to represent a tag's -#: attribute values. -_RawAttributeValues: TypeAlias = ( - "Mapping[Union[str, NamespacedAttribute], _RawAttributeValue]" -) - -#: An attribute value in its final form, as stored in the -# `Tag` class, after it has been processed and (in some cases) -# split into a list of strings. -_AttributeValue: TypeAlias = Union[str, "AttributeValueList"] - -#: A dictionary of names to :py:data:`_AttributeValue` objects. This is what -#: a tag's attributes look like after processing. -_AttributeValues: TypeAlias = Dict[str, _AttributeValue] - -#: The methods that deal with turning :py:data:`_RawAttributeValue` into -#: :py:data:`_AttributeValue` may be called several times, even after the values -#: are already processed (e.g. when cloning a tag), so they need to -#: be able to acommodate both possibilities. -_RawOrProcessedAttributeValues: TypeAlias = Union[_RawAttributeValues, _AttributeValues] - -#: A number of tree manipulation methods can take either a `PageElement` or a -#: normal Python string (which will be converted to a `NavigableString`). -_InsertableElement: TypeAlias = Union["PageElement", str] - -# Aliases to represent the many possibilities for matching bits of a -# parse tree. -# -# This is very complicated because we're applying a formal type system -# to some very DWIM code. The types we end up with will be the types -# of the arguments to the SoupStrainer constructor and (more -# familiarly to Beautiful Soup users) the find* methods. - -#: A function that takes a PageElement and returns a yes-or-no answer. -_PageElementMatchFunction: TypeAlias = Callable[["PageElement"], bool] - -#: A function that takes the raw parsed ingredients of a markup tag -#: and returns a yes-or-no answer. -# Not necessary at the moment. -# _AllowTagCreationFunction:TypeAlias = Callable[[Optional[str], str, Optional[_RawAttributeValues]], bool] - -#: A function that takes the raw parsed ingredients of a markup string node -#: and returns a yes-or-no answer. -# Not necessary at the moment. -# _AllowStringCreationFunction:TypeAlias = Callable[[Optional[str]], bool] - -#: A function that takes a `Tag` and returns a yes-or-no answer. -#: A `TagNameMatchRule` expects this kind of function, if you're -#: going to pass it a function. -_TagMatchFunction: TypeAlias = Callable[["Tag"], bool] - -#: A function that takes a single string and returns a yes-or-no -#: answer. An `AttributeValueMatchRule` expects this kind of function, if -#: you're going to pass it a function. So does a `StringMatchRule`. -_StringMatchFunction: TypeAlias = Callable[[str], bool] - -#: Either a tag name, an attribute value or a string can be matched -#: against a string, bytestring, regular expression, or a boolean. -_BaseStrainable: TypeAlias = Union[str, bytes, Pattern[str], bool] - -#: A tag can be matched either with the `_BaseStrainable` options, or -#: using a function that takes the `Tag` as its sole argument. -_BaseStrainableElement: TypeAlias = Union[_BaseStrainable, _TagMatchFunction] - -#: A tag's attribute vgalue can be matched either with the -#: `_BaseStrainable` options, or using a function that takes that -#: value as its sole argument. -_BaseStrainableAttribute: TypeAlias = Union[_BaseStrainable, _StringMatchFunction] - -#: A tag can be matched using either a single criterion or a list of -#: criteria. -_StrainableElement: TypeAlias = Union[ - _BaseStrainableElement, Iterable[_BaseStrainableElement] -] - -#: An attribute value can be matched using either a single criterion -#: or a list of criteria. -_StrainableAttribute: TypeAlias = Union[ - _BaseStrainableAttribute, Iterable[_BaseStrainableAttribute] -] - -#: An string can be matched using the same techniques as -#: an attribute value. -_StrainableString: TypeAlias = _StrainableAttribute - -#: A dictionary may be used to match against multiple attribute vlaues at once. -_StrainableAttributes: TypeAlias = Dict[str, _StrainableAttribute] - -#: Many Beautiful soup methods return a PageElement or an ResultSet of -#: PageElements. A PageElement is either a Tag or a NavigableString. -#: These convenience aliases make it easier for IDE users to see which methods -#: are available on the objects they're dealing with. -_OneElement: TypeAlias = Union["PageElement", "Tag", "NavigableString"] -_AtMostOneElement: TypeAlias = Optional[_OneElement] -_QueryResults: TypeAlias = "ResultSet[_OneElement]" diff --git a/.venv/Lib/site-packages/bs4/_warnings.py b/.venv/Lib/site-packages/bs4/_warnings.py deleted file mode 100644 index 4309473..0000000 --- a/.venv/Lib/site-packages/bs4/_warnings.py +++ /dev/null @@ -1,98 +0,0 @@ -"""Define some custom warnings.""" - - -class GuessedAtParserWarning(UserWarning): - """The warning issued when BeautifulSoup has to guess what parser to - use -- probably because no parser was specified in the constructor. - """ - - MESSAGE: str = """No parser was explicitly specified, so I'm using the best available %(markup_type)s parser for this system ("%(parser)s"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently. - -The code that caused this warning is on line %(line_number)s of the file %(filename)s. To get rid of this warning, pass the additional argument 'features="%(parser)s"' to the BeautifulSoup constructor. -""" - - -class UnusualUsageWarning(UserWarning): - """A superclass for warnings issued when Beautiful Soup sees - something that is typically the result of a mistake in the calling - code, but might be intentional on the part of the user. If it is - in fact intentional, you can filter the individual warning class - to get rid of the warning. If you don't like Beautiful Soup - second-guessing what you are doing, you can filter the - UnusualUsageWarningclass itself and get rid of these entirely. - """ - - -class MarkupResemblesLocatorWarning(UnusualUsageWarning): - """The warning issued when BeautifulSoup is given 'markup' that - actually looks like a resource locator -- a URL or a path to a file - on disk. - """ - - #: :meta private: - GENERIC_MESSAGE: str = """ - -However, if you want to parse some data that happens to look like a %(what)s, then nothing has gone wrong: you are using Beautiful Soup correctly, and this warning is spurious and can be filtered. To make this warning go away, run this code before calling the BeautifulSoup constructor: - - from bs4 import MarkupResemblesLocatorWarning - import warnings - - warnings.filterwarnings("ignore", category=MarkupResemblesLocatorWarning) - """ - - URL_MESSAGE: str = ( - """The input passed in on this line looks more like a URL than HTML or XML. - -If you meant to use Beautiful Soup to parse the web page found at a certain URL, then something has gone wrong. You should use an Python package like 'requests' to fetch the content behind the URL. Once you have the content as a string, you can feed that string into Beautiful Soup.""" - + GENERIC_MESSAGE - ) - - FILENAME_MESSAGE: str = ( - """The input passed in on this line looks more like a filename than HTML or XML. - -If you meant to use Beautiful Soup to parse the contents of a file on disk, then something has gone wrong. You should open the file first, using code like this: - - filehandle = open(your filename) - -You can then feed the open filehandle into Beautiful Soup instead of using the filename.""" - + GENERIC_MESSAGE - ) - - -class AttributeResemblesVariableWarning(UnusualUsageWarning, SyntaxWarning): - """The warning issued when Beautiful Soup suspects a provided - attribute name may actually be the misspelled name of a Beautiful - Soup variable. Generally speaking, this is only used in cases like - "_class" where it's very unlikely the user would be referencing an - XML attribute with that name. - """ - - MESSAGE: str = """%(original)r is an unusual attribute name and is a common misspelling for %(autocorrect)r. - -If you meant %(autocorrect)r, change your code to use it, and this warning will go away. - -If you really did mean to check the %(original)r attribute, this warning is spurious and can be filtered. To make it go away, run this code before creating your BeautifulSoup object: - - from bs4 import AttributeResemblesVariableWarning - import warnings - - warnings.filterwarnings("ignore", category=AttributeResemblesVariableWarning) -""" - - -class XMLParsedAsHTMLWarning(UnusualUsageWarning): - """The warning issued when an HTML parser is used to parse - XML that is not (as far as we can tell) XHTML. - """ - - MESSAGE: str = """It looks like you're using an HTML parser to parse an XML document. - -Assuming this really is an XML document, what you're doing might work, but you should know that using an XML parser will be more reliable. To parse this document as XML, make sure you have the Python package 'lxml' installed, and pass the keyword argument `features="xml"` into the BeautifulSoup constructor. - -If you want or need to use an HTML parser on this document, you can make this warning go away by filtering it. To do that, run this code before calling the BeautifulSoup constructor: - - from bs4 import XMLParsedAsHTMLWarning - import warnings - - warnings.filterwarnings("ignore", category=XMLParsedAsHTMLWarning) -""" diff --git a/.venv/Lib/site-packages/bs4/builder/__init__.py b/.venv/Lib/site-packages/bs4/builder/__init__.py deleted file mode 100644 index 5f2b38d..0000000 --- a/.venv/Lib/site-packages/bs4/builder/__init__.py +++ /dev/null @@ -1,848 +0,0 @@ -from __future__ import annotations - -# Use of this source code is governed by the MIT license. -__license__ = "MIT" - -from collections import defaultdict -import re -from types import ModuleType -from typing import ( - Any, - cast, - Dict, - Iterable, - List, - Optional, - Pattern, - Set, - Tuple, - Type, - TYPE_CHECKING, -) -import warnings -import sys -from bs4.element import ( - AttributeDict, - AttributeValueList, - CharsetMetaAttributeValue, - ContentMetaAttributeValue, - RubyParenthesisString, - RubyTextString, - Stylesheet, - Script, - TemplateString, - nonwhitespace_re, -) - -# Exceptions were moved to their own module in 4.13. Import here for -# backwards compatibility. -from bs4.exceptions import ParserRejectedMarkup - -from bs4._typing import ( - _AttributeValues, - _RawAttributeValue, -) - -from bs4._warnings import XMLParsedAsHTMLWarning - -if TYPE_CHECKING: - from bs4 import BeautifulSoup - from bs4.element import ( - NavigableString, - Tag, - ) - from bs4._typing import ( - _AttributeValue, - _Encoding, - _Encodings, - _RawOrProcessedAttributeValues, - _RawMarkup, - ) - -__all__ = [ - "HTMLTreeBuilder", - "SAXTreeBuilder", - "TreeBuilder", - "TreeBuilderRegistry", -] - -# Some useful features for a TreeBuilder to have. -FAST = "fast" -PERMISSIVE = "permissive" -STRICT = "strict" -XML = "xml" -HTML = "html" -HTML_5 = "html5" - -__all__ = [ - "TreeBuilderRegistry", - "TreeBuilder", - "HTMLTreeBuilder", - "DetectsXMLParsedAsHTML", - - "ParserRejectedMarkup", # backwards compatibility only as of 4.13.0 -] - -class TreeBuilderRegistry(object): - """A way of looking up TreeBuilder subclasses by their name or by desired - features. - """ - - builders_for_feature: Dict[str, List[Type[TreeBuilder]]] - builders: List[Type[TreeBuilder]] - - def __init__(self) -> None: - self.builders_for_feature = defaultdict(list) - self.builders = [] - - def register(self, treebuilder_class: type[TreeBuilder]) -> None: - """Register a treebuilder based on its advertised features. - - :param treebuilder_class: A subclass of `TreeBuilder`. its - `TreeBuilder.features` attribute should list its features. - """ - for feature in treebuilder_class.features: - self.builders_for_feature[feature].insert(0, treebuilder_class) - self.builders.insert(0, treebuilder_class) - - def lookup(self, *features: str) -> Optional[Type[TreeBuilder]]: - """Look up a TreeBuilder subclass with the desired features. - - :param features: A list of features to look for. If none are - provided, the most recently registered TreeBuilder subclass - will be used. - :return: A TreeBuilder subclass, or None if there's no - registered subclass with all the requested features. - """ - if len(self.builders) == 0: - # There are no builders at all. - return None - - if len(features) == 0: - # They didn't ask for any features. Give them the most - # recently registered builder. - return self.builders[0] - - # Go down the list of features in order, and eliminate any builders - # that don't match every feature. - feature_list = list(features) - feature_list.reverse() - candidates = None - candidate_set = None - while len(feature_list) > 0: - feature = feature_list.pop() - we_have_the_feature = self.builders_for_feature.get(feature, []) - if len(we_have_the_feature) > 0: - if candidates is None: - candidates = we_have_the_feature - candidate_set = set(candidates) - else: - # Eliminate any candidates that don't have this feature. - candidate_set = candidate_set.intersection(set(we_have_the_feature)) - - # The only valid candidates are the ones in candidate_set. - # Go through the original list of candidates and pick the first one - # that's in candidate_set. - if candidate_set is None or candidates is None: - return None - for candidate in candidates: - if candidate in candidate_set: - return candidate - return None - - -#: The `BeautifulSoup` constructor will take a list of features -#: and use it to look up `TreeBuilder` classes in this registry. -builder_registry: TreeBuilderRegistry = TreeBuilderRegistry() - - -class TreeBuilder(object): - """Turn a textual document into a Beautiful Soup object tree. - - This is an abstract superclass which smooths out the behavior of - different parser libraries into a single, unified interface. - - :param multi_valued_attributes: If this is set to None, the - TreeBuilder will not turn any values for attributes like - 'class' into lists. Setting this to a dictionary will - customize this behavior; look at :py:attr:`bs4.builder.HTMLTreeBuilder.DEFAULT_CDATA_LIST_ATTRIBUTES` - for an example. - - Internally, these are called "CDATA list attributes", but that - probably doesn't make sense to an end-user, so the argument name - is ``multi_valued_attributes``. - - :param preserve_whitespace_tags: A set of tags to treat - the way
 tags are treated in HTML. Tags in this set
-     are immune from pretty-printing; their contents will always be
-     output as-is.
-
-    :param string_containers: A dictionary mapping tag names to
-     the classes that should be instantiated to contain the textual
-     contents of those tags. The default is to use NavigableString
-     for every tag, no matter what the name. You can override the
-     default by changing :py:attr:`DEFAULT_STRING_CONTAINERS`.
-
-    :param store_line_numbers: If the parser keeps track of the line
-     numbers and positions of the original markup, that information
-     will, by default, be stored in each corresponding
-     :py:class:`bs4.element.Tag` object. You can turn this off by
-     passing store_line_numbers=False; then Tag.sourcepos and
-     Tag.sourceline will always be None. If the parser you're using
-     doesn't keep track of this information, then store_line_numbers
-     is irrelevant.
-
-    :param attribute_dict_class: The value of a multi-valued attribute
-      (such as HTML's 'class') willl be stored in an instance of this
-      class.  The default is Beautiful Soup's built-in
-      `AttributeValueList`, which is a normal Python list, and you
-      will probably never need to change it.
-    """
-
-    USE_DEFAULT: Any = object()  #: :meta private:
-
-    def __init__(
-        self,
-        multi_valued_attributes: Dict[str, Set[str]] = USE_DEFAULT,
-        preserve_whitespace_tags: Set[str] = USE_DEFAULT,
-        store_line_numbers: bool = USE_DEFAULT,
-        string_containers: Dict[str, Type[NavigableString]] = USE_DEFAULT,
-        empty_element_tags: Set[str] = USE_DEFAULT,
-        attribute_dict_class: Type[AttributeDict] = AttributeDict,
-        attribute_value_list_class: Type[AttributeValueList] = AttributeValueList,
-    ):
-        self.soup = None
-        if multi_valued_attributes is self.USE_DEFAULT:
-            multi_valued_attributes = self.DEFAULT_CDATA_LIST_ATTRIBUTES
-        self.cdata_list_attributes = multi_valued_attributes
-        if preserve_whitespace_tags is self.USE_DEFAULT:
-            preserve_whitespace_tags = self.DEFAULT_PRESERVE_WHITESPACE_TAGS
-        self.preserve_whitespace_tags = preserve_whitespace_tags
-        if empty_element_tags is self.USE_DEFAULT:
-            self.empty_element_tags = self.DEFAULT_EMPTY_ELEMENT_TAGS
-        else:
-            self.empty_element_tags = empty_element_tags
-        # TODO: store_line_numbers is probably irrelevant now that
-        # the behavior of sourceline and sourcepos has been made consistent
-        # everywhere.
-        if store_line_numbers == self.USE_DEFAULT:
-            store_line_numbers = self.TRACKS_LINE_NUMBERS
-        self.store_line_numbers = store_line_numbers
-        if string_containers == self.USE_DEFAULT:
-            string_containers = self.DEFAULT_STRING_CONTAINERS
-        self.string_containers = string_containers
-        self.attribute_dict_class = attribute_dict_class
-        self.attribute_value_list_class = attribute_value_list_class
-
-    NAME: str = "[Unknown tree builder]"
-    ALTERNATE_NAMES: Iterable[str] = []
-    features: Iterable[str] = []
-
-    is_xml: bool = False
-    picklable: bool = False
-
-    soup: Optional[BeautifulSoup]  #: :meta private:
-
-    #: A tag will be considered an empty-element
-    #: tag when and only when it has no contents.
-    empty_element_tags: Optional[Set[str]] = None  #: :meta private:
-    cdata_list_attributes: Dict[str, Set[str]]  #: :meta private:
-    preserve_whitespace_tags: Set[str]  #: :meta private:
-    string_containers: Dict[str, Type[NavigableString]]  #: :meta private:
-    tracks_line_numbers: bool  #: :meta private:
-
-    #: A value for these tag/attribute combinations is a space- or
-    #: comma-separated list of CDATA, rather than a single CDATA.
-    DEFAULT_CDATA_LIST_ATTRIBUTES: Dict[str, Set[str]] = defaultdict(set)
-
-    #: Whitespace should be preserved inside these tags.
-    DEFAULT_PRESERVE_WHITESPACE_TAGS: Set[str] = set()
-
-    #: The textual contents of tags with these names should be
-    #: instantiated with some class other than `bs4.element.NavigableString`.
-    DEFAULT_STRING_CONTAINERS: Dict[str, Type[bs4.element.NavigableString]] = {}
-
-    #: By default, tags are treated as empty-element tags if they have
-    #: no contents--that is, using XML rules. HTMLTreeBuilder
-    #: defines a different set of DEFAULT_EMPTY_ELEMENT_TAGS based on the
-    #: HTML 4 and HTML5 standards.
-    DEFAULT_EMPTY_ELEMENT_TAGS: Optional[Set[str]] = None
-
-    #: Most parsers don't keep track of line numbers.
-    TRACKS_LINE_NUMBERS: bool = False
-
-    def initialize_soup(self, soup: BeautifulSoup) -> None:
-        """The BeautifulSoup object has been initialized and is now
-        being associated with the TreeBuilder.
-
-        :param soup: A BeautifulSoup object.
-        """
-        self.soup = soup
-
-    def reset(self) -> None:
-        """Do any work necessary to reset the underlying parser
-        for a new document.
-
-        By default, this does nothing.
-        """
-        pass
-
-    def can_be_empty_element(self, tag_name: str) -> bool:
-        """Might a tag with this name be an empty-element tag?
-
-        The final markup may or may not actually present this tag as
-        self-closing.
-
-        For instance: an HTMLBuilder does not consider a 

tag to be - an empty-element tag (it's not in - HTMLBuilder.empty_element_tags). This means an empty

tag - will be presented as "

", not "

" or "

". - - The default implementation has no opinion about which tags are - empty-element tags, so a tag will be presented as an - empty-element tag if and only if it has no children. - "" will become "", and "bar" will - be left alone. - - :param tag_name: The name of a markup tag. - """ - if self.empty_element_tags is None: - return True - return tag_name in self.empty_element_tags - - def feed(self, markup: _RawMarkup) -> None: - """Run incoming markup through some parsing process.""" - raise NotImplementedError() - - def prepare_markup( - self, - markup: _RawMarkup, - user_specified_encoding: Optional[_Encoding] = None, - document_declared_encoding: Optional[_Encoding] = None, - exclude_encodings: Optional[_Encodings] = None, - ) -> Iterable[Tuple[_RawMarkup, Optional[_Encoding], Optional[_Encoding], bool]]: - """Run any preliminary steps necessary to make incoming markup - acceptable to the parser. - - :param markup: The markup that's about to be parsed. - :param user_specified_encoding: The user asked to try this encoding - to convert the markup into a Unicode string. - :param document_declared_encoding: The markup itself claims to be - in this encoding. NOTE: This argument is not used by the - calling code and can probably be removed. - :param exclude_encodings: The user asked *not* to try any of - these encodings. - - :yield: A series of 4-tuples: (markup, encoding, declared encoding, - has undergone character replacement) - - Each 4-tuple represents a strategy that the parser can try - to convert the document to Unicode and parse it. Each - strategy will be tried in turn. - - By default, the only strategy is to parse the markup - as-is. See `LXMLTreeBuilderForXML` and - `HTMLParserTreeBuilder` for implementations that take into - account the quirks of particular parsers. - - :meta private: - - """ - yield markup, None, None, False - - def test_fragment_to_document(self, fragment: str) -> str: - """Wrap an HTML fragment to make it look like a document. - - Different parsers do this differently. For instance, lxml - introduces an empty tag, and html5lib - doesn't. Abstracting this away lets us write simple tests - which run HTML fragments through the parser and compare the - results against other HTML fragments. - - This method should not be used outside of unit tests. - - :param fragment: A fragment of HTML. - :return: A full HTML document. - :meta private: - """ - return fragment - - def set_up_substitutions(self, tag: Tag) -> bool: - """Set up any substitutions that will need to be performed on - a `Tag` when it's output as a string. - - By default, this does nothing. See `HTMLTreeBuilder` for a - case where this is used. - - :return: Whether or not a substitution was performed. - :meta private: - """ - return False - - def _replace_cdata_list_attribute_values( - self, tag_name: str, attrs: _RawOrProcessedAttributeValues - ) -> _AttributeValues: - """When an attribute value is associated with a tag that can - have multiple values for that attribute, convert the string - value to a list of strings. - - Basically, replaces class="foo bar" with class=["foo", "bar"] - - NOTE: This method modifies its input in place. - - :param tag_name: The name of a tag. - :param attrs: A dictionary containing the tag's attributes. - Any appropriate attribute values will be modified in place. - :return: The modified dictionary that was originally passed in. - """ - - # First, cast the attrs dict to _AttributeValues. This might - # not be accurate yet, but it will be by the time this method - # returns. - modified_attrs = cast(_AttributeValues, attrs) - if not modified_attrs or not self.cdata_list_attributes: - # Nothing to do. - return modified_attrs - - # There is at least a possibility that we need to modify one of - # the attribute values. - universal: Set[str] = self.cdata_list_attributes.get("*", set()) - tag_specific = self.cdata_list_attributes.get(tag_name.lower(), None) - for attr in list(modified_attrs.keys()): - modified_value: _AttributeValue - if attr in universal or (tag_specific and attr in tag_specific): - # We have a "class"-type attribute whose string - # value is a whitespace-separated list of - # values. Split it into a list. - original_value: _AttributeValue = modified_attrs[attr] - if isinstance(original_value, _RawAttributeValue): - # This is a _RawAttributeValue (a string) that - # needs to be split and converted to a - # AttributeValueList so it can be an - # _AttributeValue. - modified_value = self.attribute_value_list_class( - nonwhitespace_re.findall(original_value) - ) - else: - # html5lib calls setAttributes twice for the - # same tag when rearranging the parse tree. On - # the second call the attribute value here is - # already a list. This can also happen when a - # Tag object is cloned. If this happens, leave - # the value alone rather than trying to split - # it again. - modified_value = original_value - modified_attrs[attr] = modified_value - return modified_attrs - - -class SAXTreeBuilder(TreeBuilder): - """A Beautiful Soup treebuilder that listens for SAX events. - - This is not currently used for anything, and it will be removed - soon. It was a good idea, but it wasn't properly integrated into the - rest of Beautiful Soup, so there have been long stretches where it - hasn't worked properly. - """ - - def __init__(self, *args: Any, **kwargs: Any) -> None: - warnings.warn( - "The SAXTreeBuilder class was deprecated in 4.13.0 and will be removed soon thereafter. It is completely untested and probably doesn't work; do not use it.", - DeprecationWarning, - stacklevel=2, - ) - super(SAXTreeBuilder, self).__init__(*args, **kwargs) - - def feed(self, markup: _RawMarkup) -> None: - raise NotImplementedError() - - def close(self) -> None: - pass - - def startElement(self, name: str, attrs: Dict[str, str]) -> None: - attrs = AttributeDict((key[1], value) for key, value in list(attrs.items())) - # print("Start %s, %r" % (name, attrs)) - assert self.soup is not None - self.soup.handle_starttag(name, None, None, attrs) - - def endElement(self, name: str) -> None: - # print("End %s" % name) - assert self.soup is not None - self.soup.handle_endtag(name) - - def startElementNS( - self, nsTuple: Tuple[str, str], nodeName: str, attrs: Dict[str, str] - ) -> None: - # Throw away (ns, nodeName) for now. - self.startElement(nodeName, attrs) - - def endElementNS(self, nsTuple: Tuple[str, str], nodeName: str) -> None: - # Throw away (ns, nodeName) for now. - self.endElement(nodeName) - # handler.endElementNS((ns, node.nodeName), node.nodeName) - - def startPrefixMapping(self, prefix: str, nodeValue: str) -> None: - # Ignore the prefix for now. - pass - - def endPrefixMapping(self, prefix: str) -> None: - # Ignore the prefix for now. - # handler.endPrefixMapping(prefix) - pass - - def characters(self, content: str) -> None: - assert self.soup is not None - self.soup.handle_data(content) - - def startDocument(self) -> None: - pass - - def endDocument(self) -> None: - pass - - -class HTMLTreeBuilder(TreeBuilder): - """This TreeBuilder knows facts about HTML, such as which tags are treated - specially by the HTML standard. - """ - - #: Some HTML tags are defined as having no contents. Beautiful Soup - #: treats these specially. - DEFAULT_EMPTY_ELEMENT_TAGS: Set[str] = set( - [ - # These are from HTML5. - "area", - "base", - "br", - "col", - "embed", - "hr", - "img", - "input", - "keygen", - "link", - "menuitem", - "meta", - "param", - "source", - "track", - "wbr", - # These are from earlier versions of HTML and are removed in HTML5. - "basefont", - "bgsound", - "command", - "frame", - "image", - "isindex", - "nextid", - "spacer", - ] - ) - - #: The HTML standard defines these tags as block-level elements. Beautiful - #: Soup does not treat these elements differently from other elements, - #: but it may do so eventually, and this information is available if - #: you need to use it. - DEFAULT_BLOCK_ELEMENTS: Set[str] = set( - [ - "address", - "article", - "aside", - "blockquote", - "canvas", - "dd", - "div", - "dl", - "dt", - "fieldset", - "figcaption", - "figure", - "footer", - "form", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "header", - "hr", - "li", - "main", - "nav", - "noscript", - "ol", - "output", - "p", - "pre", - "section", - "table", - "tfoot", - "ul", - "video", - ] - ) - - #: These HTML tags need special treatment so they can be - #: represented by a string class other than `bs4.element.NavigableString`. - #: - #: For some of these tags, it's because the HTML standard defines - #: an unusual content model for them. I made this list by going - #: through the HTML spec - #: (https://html.spec.whatwg.org/#metadata-content) and looking for - #: "metadata content" elements that can contain strings. - #: - #: The Ruby tags ( and ) are here despite being normal - #: "phrasing content" tags, because the content they contain is - #: qualitatively different from other text in the document, and it - #: can be useful to be able to distinguish it. - #: - #: TODO: Arguably

foo

" - soup = self.soup(markup) - return doctype.encode("utf8"), soup - - def test_normal_doctypes(self): - """Make sure normal, everyday HTML doctypes are handled correctly.""" - self.assertDoctypeHandled("html") - self.assertDoctypeHandled( - 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' - ) - - def test_empty_doctype(self): - soup = self.soup("") - doctype = soup.contents[0] - assert "" == doctype.strip() - - def test_mixed_case_doctype(self): - # A lowercase or mixed-case doctype becomes a Doctype. - for doctype_fragment in ("doctype", "DocType"): - doctype_str, soup = self._document_with_doctype("html", doctype_fragment) - - # Make sure a Doctype object was created and that the DOCTYPE - # is uppercase. - doctype = soup.contents[0] - assert doctype.__class__ == Doctype - assert doctype == "html" - assert soup.encode("utf8")[: len(doctype_str)] == b"" - - # Make sure that the doctype was correctly associated with the - # parse tree and that the rest of the document parsed. - assert soup.p.contents[0] == "foo" - - def test_public_doctype_with_url(self): - doctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"' - self.assertDoctypeHandled(doctype) - - def test_system_doctype(self): - self.assertDoctypeHandled('foo SYSTEM "http://www.example.com/"') - - def test_namespaced_system_doctype(self): - # We can handle a namespaced doctype with a system ID. - self.assertDoctypeHandled('xsl:stylesheet SYSTEM "htmlent.dtd"') - - def test_namespaced_public_doctype(self): - # Test a namespaced doctype with a public id. - self.assertDoctypeHandled('xsl:stylesheet PUBLIC "htmlent.dtd"') - - def test_real_xhtml_document(self): - """A real XHTML document should come out more or less the same as it went in.""" - markup = b""" - - -Hello. -Goodbye. -""" - with warnings.catch_warnings(record=True) as w: - soup = self.soup(markup) - assert soup.encode("utf-8").replace(b"\n", b"") == markup.replace(b"\n", b"") - - # No warning was issued about parsing an XML document as HTML, - # because XHTML is both. - assert w == [] - - def test_namespaced_html(self): - # When a namespaced XML document is parsed as HTML it should - # be treated as HTML with weird tag names. - markup = b"""content""" - with warnings.catch_warnings(record=True) as w: - soup = self.soup(markup) - - assert 2 == len(soup.find_all("ns1:foo")) - - # n.b. no "you're parsing XML as HTML" warning was given - # because there was no XML declaration. - assert [] == w - - def test_detect_xml_parsed_as_html(self): - # A warning is issued when parsing an XML document as HTML, - # but basic stuff should still work. - markup = b"""string""" - with warnings.catch_warnings(record=True) as w: - soup = self.soup(markup) - assert soup.tag.string == "string" - [warning] = w - assert isinstance(warning.message, XMLParsedAsHTMLWarning) - assert str(warning.message) == XMLParsedAsHTMLWarning.MESSAGE - - # NOTE: the warning is not issued if the document appears to - # be XHTML (tested with test_real_xhtml_document in the - # superclass) or if there is no XML declaration (tested with - # test_namespaced_html in the superclass). - - def test_processing_instruction(self): - # We test both Unicode and bytestring to verify that - # process_markup correctly sets processing_instruction_class - # even when the markup is already Unicode and there is no - # need to process anything. - markup = """""" - soup = self.soup(markup) - assert markup == soup.decode() - - markup = b"""""" - soup = self.soup(markup) - assert markup == soup.encode("utf8") - - def test_deepcopy(self): - """Make sure you can copy the tree builder. - - This is important because the builder is part of a - BeautifulSoup object, and we want to be able to copy that. - """ - copy.deepcopy(self.default_builder) - - def test_p_tag_is_never_empty_element(self): - """A

tag is never designated as an empty-element tag. - - Even if the markup shows it as an empty-element tag, it - shouldn't be presented that way. - """ - soup = self.soup("

") - assert not soup.p.is_empty_element - assert str(soup.p) == "

" - - def test_unclosed_tags_get_closed(self): - """A tag that's not closed by the end of the document should be closed. - - This applies to all tags except empty-element tags. - """ - self.assert_soup("

", "

") - self.assert_soup("", "") - - self.assert_soup("
", "
") - - def test_br_is_always_empty_element_tag(self): - """A
tag is designated as an empty-element tag. - - Some parsers treat

as one
tag, some parsers as - two tags, but it should always be an empty-element tag. - """ - soup = self.soup("

") - assert soup.br.is_empty_element - assert str(soup.br) == "
" - - def test_nested_formatting_elements(self): - self.assert_soup("") - - def test_double_head(self): - html = """ - - -Ordinary HEAD element test - - - -Hello, world! - - -""" - soup = self.soup(html) - assert "text/javascript" == soup.find("script")["type"] - - def test_comment(self): - # Comments are represented as Comment objects. - markup = "

foobaz

" - self.assert_soup(markup) - - soup = self.soup(markup) - comment = soup.find(string="foobar") - assert comment.__class__ == Comment - - # The comment is properly integrated into the tree. - foo = soup.find(string="foo") - assert comment == foo.next_element - baz = soup.find(string="baz") - assert comment == baz.previous_element - - def test_preserved_whitespace_in_pre_and_textarea(self): - """Whitespace must be preserved in
 and \n"
-        self.assert_soup(pre_markup)
-        self.assert_soup(textarea_markup)
-
-        soup = self.soup(pre_markup)
-        assert soup.pre.prettify() == pre_markup
-
-        soup = self.soup(textarea_markup)
-        assert soup.textarea.prettify() == textarea_markup
-
-        soup = self.soup("")
-        assert soup.textarea.prettify() == "\n"
-
-    def test_nested_inline_elements(self):
-        """Inline elements can be nested indefinitely."""
-        b_tag = "Inside a B tag"
-        self.assert_soup(b_tag)
-
-        nested_b_tag = "

A nested tag

" - self.assert_soup(nested_b_tag) - - double_nested_b_tag = "

A doubly nested tag

" - self.assert_soup(double_nested_b_tag) - - def test_nested_block_level_elements(self): - """Block elements can be nested.""" - soup = self.soup("

Foo

") - blockquote = soup.blockquote - assert blockquote.p.b.string == "Foo" - assert blockquote.b.string == "Foo" - - def test_correctly_nested_tables(self): - """One table can go inside another one.""" - markup = ( - '' - "" - "" - ) - - self.assert_soup( - markup, - '
Here's another table:" - '' - "" - "
foo
Here\'s another table:' - '
foo
' - "
", - ) - - self.assert_soup( - "" - "" - "
Foo
Bar
Baz
" - ) - - def test_multivalued_attribute_with_whitespace(self): - # Whitespace separating the values of a multi-valued attribute - # should be ignored. - - markup = '
' - soup = self.soup(markup) - assert ["foo", "bar"] == soup.div["class"] - - # If you search by the literal name of the class it's like the whitespace - # wasn't there. - assert soup.div == soup.find("div", class_="foo bar") - - def test_deeply_nested_multivalued_attribute(self): - # html5lib can set the attributes of the same tag many times - # as it rearranges the tree. This has caused problems with - # multivalued attributes. - markup = '
' - soup = self.soup(markup) - assert ["css"] == soup.div.div["class"] - - def test_multivalued_attribute_on_html(self): - # html5lib uses a different API to set the attributes ot the - # tag. This has caused problems with multivalued - # attributes. - markup = '' - soup = self.soup(markup) - assert ["a", "b"] == soup.html["class"] - - def test_angle_brackets_in_attribute_values_are_escaped(self): - self.assert_soup('', '') - - def test_strings_resembling_character_entity_references(self): - # "&T" and "&p" look like incomplete character entities, but they are - # not. - self.assert_soup( - "

• AT&T is in the s&p 500

", - "

\u2022 AT&T is in the s&p 500

", - ) - - def test_apos_entity(self): - self.assert_soup( - "

Bob's Bar

", - "

Bob's Bar

", - ) - - def test_entities_in_foreign_document_encoding(self): - # “ and ” are invalid numeric entities referencing - # Windows-1252 characters. - references a character common - # to Windows-1252 and Unicode, and ☃ references a - # character only found in Unicode. - # - # All of these entities should be converted to Unicode - # characters. - markup = "

“Hello” -☃

" - soup = self.soup(markup) - assert "“Hello” -☃" == soup.p.string - - def test_entities_in_attributes_converted_to_unicode(self): - expect = '

' - self.assert_soup('

', expect) - self.assert_soup('

', expect) - self.assert_soup('

', expect) - self.assert_soup('

', expect) - - def test_entities_in_text_converted_to_unicode(self): - expect = "

pi\N{LATIN SMALL LETTER N WITH TILDE}ata

" - self.assert_soup("

piñata

", expect) - self.assert_soup("

piñata

", expect) - self.assert_soup("

piñata

", expect) - self.assert_soup("

piñata

", expect) - - def test_quot_entity_converted_to_quotation_mark(self): - self.assert_soup( - "

I said "good day!"

", '

I said "good day!"

' - ) - - def test_out_of_range_entity(self): - expect = "\N{REPLACEMENT CHARACTER}" - self.assert_soup("�", expect) - self.assert_soup("�", expect) - self.assert_soup("�", expect) - - def test_multipart_strings(self): - "Mostly to prevent a recurrence of a bug in the html5lib treebuilder." - soup = self.soup("

\nfoo

") - assert "p" == soup.h2.string.next_element.name - assert "p" == soup.p.name - self.assertConnectedness(soup) - - def test_invalid_html_entity(self): - # The html.parser treebuilder can't distinguish between an - # invalid HTML entity with a semicolon and an invalid HTML - # entity with no semicolon (see its subclass for the tested - # behavior). But the other treebuilders can. - markup = "

a &nosuchentity b

" - soup = self.soup(markup) - assert "

a &nosuchentity b

" == soup.p.decode() - - markup = "

a &nosuchentity; b

" - soup = self.soup(markup) - assert "

a &nosuchentity; b

" == soup.p.decode() - - def test_head_tag_between_head_and_body(self): - "Prevent recurrence of a bug in the html5lib treebuilder." - content = """ - - foo - -""" - soup = self.soup(content) - assert soup.html.body is not None - self.assertConnectedness(soup) - - def test_multiple_copies_of_a_tag(self): - "Prevent recurrence of a bug in the html5lib treebuilder." - content = """ - - - - - -""" - soup = self.soup(content) - self.assertConnectedness(soup.article) - - def test_basic_namespaces(self): - """Parsers don't need to *understand* namespaces, but at the - very least they should not choke on namespaces or lose - data.""" - - markup = b'4' - soup = self.soup(markup) - assert markup == soup.encode() - assert "http://www.w3.org/1999/xhtml" == soup.html["xmlns"] - assert "http://www.w3.org/1998/Math/MathML" == soup.html["xmlns:mathml"] - assert "http://www.w3.org/2000/svg" == soup.html["xmlns:svg"] - - def test_multivalued_attribute_value_becomes_list(self): - markup = b'' - soup = self.soup(markup) - assert ["foo", "bar"] == soup.a["class"] - - # - # Generally speaking, tests below this point are more tests of - # Beautiful Soup than tests of the tree builders. But parsers are - # weird, so we run these tests separately for every tree builder - # to detect any differences between them. - # - - def test_can_parse_unicode_document(self): - # A seemingly innocuous document... but it's in Unicode! And - # it contains characters that can't be represented in the - # encoding found in the declaration! The horror! - markup = 'Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!' - soup = self.soup(markup) - assert "Sacr\xe9 bleu!" == soup.body.string - - def test_soupstrainer(self): - """Parsers should be able to work with SoupStrainers.""" - strainer = SoupStrainer("b") - soup = self.soup("A bold statement", parse_only=strainer) - assert soup.decode() == "bold" - - def test_single_quote_attribute_values_become_double_quotes(self): - self.assert_soup("", '') - - def test_attribute_values_with_nested_quotes_are_left_alone(self): - text = """a""" - self.assert_soup(text) - - def test_attribute_values_with_double_nested_quotes_get_quoted(self): - text = """a""" - soup = self.soup(text) - soup.foo["attr"] = 'Brawls happen at "Bob\'s Bar"' - self.assert_soup( - soup.foo.decode(), - """a""", - ) - - def test_ampersand_in_attribute_value_gets_escaped(self): - self.assert_soup( - '', - '', - ) - - self.assert_soup( - 'foo', - 'foo', - ) - - def test_escaped_ampersand_in_attribute_value_is_left_alone(self): - self.assert_soup('') - - def test_entities_in_strings_converted_during_parsing(self): - # Both XML and HTML entities are converted to Unicode characters - # during parsing. - text = "

<<sacré bleu!>>

" - expected = ( - "

<<sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!>>

" - ) - self.assert_soup(text, expected) - - def test_smart_quotes_converted_on_the_way_in(self): - # Microsoft smart quotes are converted to Unicode characters during - # parsing. - quote = b"

\x91Foo\x92

" - soup = self.soup(quote, from_encoding="windows-1252") - assert ( - soup.p.string - == "\N{LEFT SINGLE QUOTATION MARK}Foo\N{RIGHT SINGLE QUOTATION MARK}" - ) - - def test_non_breaking_spaces_converted_on_the_way_in(self): - soup = self.soup("  ") - assert soup.a.string == "\N{NO-BREAK SPACE}" * 2 - - def test_entities_converted_on_the_way_out(self): - text = "

<<sacré bleu!>>

" - expected = "

<<sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!>>

".encode( - "utf-8" - ) - soup = self.soup(text) - assert soup.p.encode("utf-8") == expected - - def test_real_iso_8859_document(self): - # Smoke test of interrelated functionality, using an - # easy-to-understand document. - - # Here it is in Unicode. Note that it claims to be in ISO-8859-1. - unicode_html = '

Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!

' - - # That's because we're going to encode it into ISO-8859-1, - # and use that to test. - iso_latin_html = unicode_html.encode("iso-8859-1") - - # Parse the ISO-8859-1 HTML. - soup = self.soup(iso_latin_html) - - # Encode it to UTF-8. - result = soup.encode("utf-8") - - # What do we expect the result to look like? Well, it would - # look like unicode_html, except that the META tag would say - # UTF-8 instead of ISO-8859-1. - expected = unicode_html.replace("ISO-8859-1", "utf-8") - - # And, of course, it would be in UTF-8, not Unicode. - expected = expected.encode("utf-8") - - # Ta-da! - assert result == expected - - def test_real_shift_jis_document(self): - # Smoke test to make sure the parser can handle a document in - # Shift-JIS encoding, without choking. - shift_jis_html = ( - b"
"
-            b"\x82\xb1\x82\xea\x82\xcdShift-JIS\x82\xc5\x83R\x81[\x83f"
-            b"\x83B\x83\x93\x83O\x82\xb3\x82\xea\x82\xbd\x93\xfa\x96{\x8c"
-            b"\xea\x82\xcc\x83t\x83@\x83C\x83\x8b\x82\xc5\x82\xb7\x81B"
-            b"
" - ) - unicode_html = shift_jis_html.decode("shift-jis") - soup = self.soup(unicode_html) - - # Make sure the parse tree is correctly encoded to various - # encodings. - assert soup.encode("utf-8") == unicode_html.encode("utf-8") - assert soup.encode("euc_jp") == unicode_html.encode("euc_jp") - - def test_real_hebrew_document(self): - # A real-world test to make sure we can convert ISO-8859-9 (a - # Hebrew encoding) to UTF-8. - hebrew_document = b"Hebrew (ISO 8859-8) in Visual Directionality

Hebrew (ISO 8859-8) in Visual Directionality

\xed\xe5\xec\xf9" - soup = self.soup(hebrew_document, from_encoding="iso8859-8") - # Some tree builders call it iso8859-8, others call it iso-8859-9. - # That's not a difference we really care about. - assert soup.original_encoding in ("iso8859-8", "iso-8859-8") - assert soup.encode("utf-8") == ( - hebrew_document.decode("iso8859-8").encode("utf-8") - ) - - def test_meta_tag_reflects_current_encoding(self): - # Here's the tag saying that a document is - # encoded in Shift-JIS. - meta_tag = ( - '' - ) - - # Here's a document incorporating that meta tag. - shift_jis_html = ( - "\n%s\n" - '' - "Shift-JIS markup goes here." - ) % meta_tag - soup = self.soup(shift_jis_html) - - # Parse the document, and the charset is seemingly unaffected. - parsed_meta = soup.find("meta", {"http-equiv": "Content-type"}) - content = parsed_meta["content"] - assert "text/html; charset=x-sjis" == content - - # But that value is actually a ContentMetaAttributeValue object. - assert isinstance(content, ContentMetaAttributeValue) - - # And it will take on a value that reflects its current - # encoding. - assert "text/html; charset=utf8" == content.substitute_encoding("utf8") - - # No matter how the tag is encoded, its charset attribute - # will always be accurate. - assert b"charset=utf8" in parsed_meta.encode("utf8") - assert b"charset=shift-jis" in parsed_meta.encode("shift-jis") - - # For the rest of the story, see TestSubstitutions in - # test_tree.py. - - def test_html5_style_meta_tag_reflects_current_encoding(self): - # Here's the tag saying that a document is - # encoded in Shift-JIS. - meta_tag = '' - - # Here's a document incorporating that meta tag. - shift_jis_html = ( - "\n%s\n" - '' - "Shift-JIS markup goes here." - ) % meta_tag - soup = self.soup(shift_jis_html) - - # Parse the document, and the charset is seemingly unaffected. - parsed_meta = soup.find("meta", id="encoding") - charset = parsed_meta["charset"] - assert "x-sjis" == charset - - # But that value is actually a CharsetMetaAttributeValue object. - assert isinstance(charset, CharsetMetaAttributeValue) - - # And it will take on a value that reflects its current - # encoding. - assert "utf8" == charset.substitute_encoding("utf8") - - # No matter how the tag is encoded, its charset attribute - # will always be accurate. - assert b'charset="utf8"' in parsed_meta.encode("utf8") - assert b'charset="shift-jis"' in parsed_meta.encode("shift-jis") - - def test_python_specific_encodings_not_used_in_charset(self): - # You can encode an HTML document using a Python-specific - # encoding, but that encoding won't be mentioned _inside_ the - # resulting document. Instead, the document will appear to - # have no encoding. - for markup in [ - b'' b'' - ]: - soup = self.soup(markup) - for encoding in PYTHON_SPECIFIC_ENCODINGS: - if encoding in ( - "idna", - "mbcs", - "oem", - "undefined", - "string_escape", - "string-escape", - ): - # For one reason or another, these will raise an - # exception if we actually try to use them, so don't - # bother. - continue - encoded = soup.encode(encoding) - assert b'meta charset=""' in encoded - assert encoding.encode("ascii") not in encoded - - def test_tag_with_no_attributes_can_have_attributes_added(self): - data = self.soup("text") - data.a["foo"] = "bar" - assert 'text' == data.a.decode() - - def test_closing_tag_with_no_opening_tag(self): - # Without BeautifulSoup.open_tag_counter, the tag will - # cause _popToTag to be called over and over again as we look - # for a tag that wasn't there. The result is that 'text2' - # will show up outside the body of the document. - soup = self.soup("

text1

text2
") - assert "

text1

text2
" == soup.body.decode() - - def test_worst_case(self): - """Test the worst case (currently) for linking issues.""" - - soup = self.soup(BAD_DOCUMENT) - self.linkage_validator(soup) - - -class XMLTreeBuilderSmokeTest(TreeBuilderSmokeTest): - def test_pickle_and_unpickle_identity(self): - # Pickling a tree, then unpickling it, yields a tree identical - # to the original. - tree = self.soup("foo") - dumped = pickle.dumps(tree, 2) - loaded = pickle.loads(dumped) - assert loaded.__class__ == BeautifulSoup - assert loaded.decode() == tree.decode() - - def test_docstring_generated(self): - soup = self.soup("") - assert soup.encode() == b'\n' - - def test_xml_declaration(self): - markup = b"""\n""" - soup = self.soup(markup) - assert markup == soup.encode("utf8") - - def test_python_specific_encodings_not_used_in_xml_declaration(self): - # You can encode an XML document using a Python-specific - # encoding, but that encoding won't be mentioned _inside_ the - # resulting document. - markup = b"""\n""" - soup = self.soup(markup) - for encoding in PYTHON_SPECIFIC_ENCODINGS: - if encoding in ( - "idna", - "mbcs", - "oem", - "undefined", - "string_escape", - "string-escape", - ): - # For one reason or another, these will raise an - # exception if we actually try to use them, so don't - # bother. - continue - encoded = soup.encode(encoding) - assert b'' in encoded - assert encoding.encode("ascii") not in encoded - - def test_processing_instruction(self): - markup = b"""\n""" - soup = self.soup(markup) - assert markup == soup.encode("utf8") - - def test_real_xhtml_document(self): - """A real XHTML document should come out *exactly* the same as it went in.""" - markup = b""" - - -Hello. -Goodbye. -""" - soup = self.soup(markup) - assert soup.encode("utf-8") == markup - - def test_nested_namespaces(self): - doc = b""" - - - - - -""" - soup = self.soup(doc) - assert doc == soup.encode() - - def test_formatter_processes_script_tag_for_xml_documents(self): - doc = """ - -""" - soup = BeautifulSoup(doc, "lxml-xml") - # lxml would have stripped this while parsing, but we can add - # it later. - soup.script.string = 'console.log("< < hey > > ");' - encoded = soup.encode() - assert b"< < hey > >" in encoded - - def test_can_parse_unicode_document(self): - markup = 'Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!' - soup = self.soup(markup) - assert "Sacr\xe9 bleu!" == soup.root.string - - def test_can_parse_unicode_document_begining_with_bom(self): - markup = '\N{BYTE ORDER MARK}Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!' - soup = self.soup(markup) - assert "Sacr\xe9 bleu!" == soup.root.string - - def test_popping_namespaced_tag(self): - markup = 'b2012-07-02T20:33:42Zcd' - soup = self.soup(markup) - assert str(soup.rss) == markup - - def test_docstring_includes_correct_encoding(self): - soup = self.soup("") - assert ( - soup.encode("latin1") == b'\n' - ) - - def test_large_xml_document(self): - """A large XML document should come out the same as it went in.""" - markup = ( - b'\n' - + b"0" * (2**12) - + b"" - ) - soup = self.soup(markup) - assert soup.encode("utf-8") == markup - - def test_tags_are_empty_element_if_and_only_if_they_are_empty(self): - self.assert_soup("

", "

") - self.assert_soup("

foo

") - - def test_namespaces_are_preserved(self): - markup = 'This tag is in the a namespaceThis tag is in the b namespace' - soup = self.soup(markup) - root = soup.root - assert "http://example.com/" == root["xmlns:a"] - assert "http://example.net/" == root["xmlns:b"] - - def test_closing_namespaced_tag(self): - markup = '

20010504

' - soup = self.soup(markup) - assert str(soup.p) == markup - - def test_namespaced_attributes(self): - markup = '' - soup = self.soup(markup) - assert str(soup.foo) == markup - - def test_namespaced_attributes_xml_namespace(self): - markup = 'bar' - soup = self.soup(markup) - assert str(soup.foo) == markup - - def test_find_by_prefixed_name(self): - doc = """ - - foo - bar - baz - -""" - soup = self.soup(doc) - - # There are three tags. - assert 3 == len(soup.find_all("tag")) - - # But two of them are ns1:tag and one of them is ns2:tag. - assert 2 == len(soup.find_all("ns1:tag")) - assert 1 == len(soup.find_all("ns2:tag")) - - assert 1, len(soup.find_all("ns2:tag", key="value")) - assert 3, len(soup.find_all(["ns1:tag", "ns2:tag"])) - - def test_copy_tag_preserves_namespace(self): - xml = """ -""" - - soup = self.soup(xml) - tag = soup.document - duplicate = copy.copy(tag) - - # The two tags have the same namespace prefix. - assert tag.prefix == duplicate.prefix - - def test_worst_case(self): - """Test the worst case (currently) for linking issues.""" - - soup = self.soup(BAD_DOCUMENT) - self.linkage_validator(soup) - - -class HTML5TreeBuilderSmokeTest(HTMLTreeBuilderSmokeTest): - """Smoke test for a tree builder that supports HTML5.""" - - def test_real_xhtml_document(self): - # Since XHTML is not HTML5, HTML5 parsers are not tested to handle - # XHTML documents in any particular way. - pass - - def test_html_tags_have_namespace(self): - markup = "" - soup = self.soup(markup) - assert "http://www.w3.org/1999/xhtml" == soup.a.namespace - - def test_svg_tags_have_namespace(self): - markup = "" - soup = self.soup(markup) - namespace = "http://www.w3.org/2000/svg" - assert namespace == soup.svg.namespace - assert namespace == soup.circle.namespace - - def test_mathml_tags_have_namespace(self): - markup = "5" - soup = self.soup(markup) - namespace = "http://www.w3.org/1998/Math/MathML" - assert namespace == soup.math.namespace - assert namespace == soup.msqrt.namespace - - def test_xml_declaration_becomes_comment(self): - markup = '' - soup = self.soup(markup) - assert isinstance(soup.contents[0], Comment) - assert soup.contents[0] == '?xml version="1.0" encoding="utf-8"?' - assert "html" == soup.contents[0].next_element.name diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/__init__.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 35e1dc2..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_builder.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_builder.cpython-312.pyc deleted file mode 100644 index e8fe1a0..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_builder.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_builder_registry.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_builder_registry.cpython-312.pyc deleted file mode 100644 index b42bab9..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_builder_registry.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_css.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_css.cpython-312.pyc deleted file mode 100644 index 67613a3..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_css.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_dammit.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_dammit.cpython-312.pyc deleted file mode 100644 index 138b327..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_dammit.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_element.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_element.cpython-312.pyc deleted file mode 100644 index 6ac207f..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_element.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_filter.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_filter.cpython-312.pyc deleted file mode 100644 index 3d731d7..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_filter.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_formatter.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_formatter.cpython-312.pyc deleted file mode 100644 index 4651c8f..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_formatter.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_fuzz.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_fuzz.cpython-312.pyc deleted file mode 100644 index ea41f15..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_fuzz.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_html5lib.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_html5lib.cpython-312.pyc deleted file mode 100644 index f4ade48..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_html5lib.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_htmlparser.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_htmlparser.cpython-312.pyc deleted file mode 100644 index 79d4657..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_htmlparser.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_lxml.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_lxml.cpython-312.pyc deleted file mode 100644 index b835f86..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_lxml.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_navigablestring.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_navigablestring.cpython-312.pyc deleted file mode 100644 index 8f99e09..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_navigablestring.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_pageelement.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_pageelement.cpython-312.pyc deleted file mode 100644 index a535dda..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_pageelement.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_soup.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_soup.cpython-312.pyc deleted file mode 100644 index 1bdee6f..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_soup.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_tag.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_tag.cpython-312.pyc deleted file mode 100644 index fe093d3..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_tag.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_tree.cpython-312.pyc b/.venv/Lib/site-packages/bs4/tests/__pycache__/test_tree.cpython-312.pyc deleted file mode 100644 index 8da3b2b..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/__pycache__/test_tree.cpython-312.pyc and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-4670634698080256.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-4670634698080256.testcase deleted file mode 100644 index 4828f8a..0000000 --- a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-4670634698080256.testcase +++ /dev/null @@ -1 +0,0 @@ -

\ No newline at end of file diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5000587759190016.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5000587759190016.testcase deleted file mode 100644 index 8a585ce..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5000587759190016.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5167584867909632.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5167584867909632.testcase deleted file mode 100644 index 0fe66dd..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5167584867909632.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5270998950477824.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5270998950477824.testcase deleted file mode 100644 index fd41142..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5270998950477824.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5375146639360000.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5375146639360000.testcase deleted file mode 100644 index 6248b2c..0000000 --- a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5375146639360000.testcase +++ /dev/null @@ -1 +0,0 @@ - >tet>< \ No newline at end of file diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5492400320282624.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5492400320282624.testcase deleted file mode 100644 index 107da53..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5492400320282624.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5703933063462912.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5703933063462912.testcase deleted file mode 100644 index 367106c..0000000 --- a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-5703933063462912.testcase +++ /dev/null @@ -1,2 +0,0 @@ - -t \ No newline at end of file diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6450958476902400.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6450958476902400.testcase deleted file mode 100644 index a823d55..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6450958476902400.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6600557255327744.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6600557255327744.testcase deleted file mode 100644 index 65af44d..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/clusterfuzz-testcase-minimized-bs4_fuzzer-6600557255327744.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/crash-0d306a50c8ed8bcd0785b67000fcd5dea1d33f08.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/crash-0d306a50c8ed8bcd0785b67000fcd5dea1d33f08.testcase deleted file mode 100644 index 5559adb..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/crash-0d306a50c8ed8bcd0785b67000fcd5dea1d33f08.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/fuzz/crash-ffbdfa8a2b26f13537b68d3794b0478a4090ee4a.testcase b/.venv/Lib/site-packages/bs4/tests/fuzz/crash-ffbdfa8a2b26f13537b68d3794b0478a4090ee4a.testcase deleted file mode 100644 index 8857115..0000000 Binary files a/.venv/Lib/site-packages/bs4/tests/fuzz/crash-ffbdfa8a2b26f13537b68d3794b0478a4090ee4a.testcase and /dev/null differ diff --git a/.venv/Lib/site-packages/bs4/tests/test_builder.py b/.venv/Lib/site-packages/bs4/tests/test_builder.py deleted file mode 100644 index 87d6758..0000000 --- a/.venv/Lib/site-packages/bs4/tests/test_builder.py +++ /dev/null @@ -1,28 +0,0 @@ -import pytest -from unittest.mock import patch -from bs4.builder import DetectsXMLParsedAsHTML - - -class TestDetectsXMLParsedAsHTML: - @pytest.mark.parametrize( - "markup,looks_like_xml", - [ - ("No xml declaration", False), - ("obviously HTMLActually XHTML", False), - (" < html>Tricky XHTML", False), - ("", True), - ], - ) - def test_warn_if_markup_looks_like_xml(self, markup, looks_like_xml): - # Test of our ability to guess at whether markup looks XML-ish - # _and_ not HTML-ish. - with patch("bs4.builder.DetectsXMLParsedAsHTML._warn") as mock: - for data in markup, markup.encode("utf8"): - result = DetectsXMLParsedAsHTML.warn_if_markup_looks_like_xml(data) - assert result == looks_like_xml - if looks_like_xml: - assert mock.called - else: - assert not mock.called - mock.reset_mock() diff --git a/.venv/Lib/site-packages/bs4/tests/test_builder_registry.py b/.venv/Lib/site-packages/bs4/tests/test_builder_registry.py deleted file mode 100644 index ad4b5a9..0000000 --- a/.venv/Lib/site-packages/bs4/tests/test_builder_registry.py +++ /dev/null @@ -1,139 +0,0 @@ -"""Tests of the builder registry.""" - -import pytest -import warnings -from typing import Type - -from bs4 import BeautifulSoup -from bs4.builder import ( - builder_registry as registry, - TreeBuilder, - TreeBuilderRegistry, -) -from bs4.builder._htmlparser import HTMLParserTreeBuilder - -from . import ( - HTML5LIB_PRESENT, - LXML_PRESENT, -) - -if HTML5LIB_PRESENT: - from bs4.builder._html5lib import HTML5TreeBuilder - -if LXML_PRESENT: - from bs4.builder._lxml import ( - LXMLTreeBuilderForXML, - LXMLTreeBuilder, - ) - - -# TODO: Split out the lxml and html5lib tests into their own classes -# and gate with pytest.mark.skipIf. -class TestBuiltInRegistry(object): - """Test the built-in registry with the default builders registered.""" - - def test_combination(self): - assert registry.lookup("strict", "html") == HTMLParserTreeBuilder - if LXML_PRESENT: - assert registry.lookup("fast", "html") == LXMLTreeBuilder - assert registry.lookup("permissive", "xml") == LXMLTreeBuilderForXML - if HTML5LIB_PRESENT: - assert registry.lookup("html5lib", "html") == HTML5TreeBuilder - - def test_lookup_by_markup_type(self): - if LXML_PRESENT: - assert registry.lookup("html") == LXMLTreeBuilder - assert registry.lookup("xml") == LXMLTreeBuilderForXML - else: - assert registry.lookup("xml") is None - if HTML5LIB_PRESENT: - assert registry.lookup("html") == HTML5TreeBuilder - else: - assert registry.lookup("html") == HTMLParserTreeBuilder - - def test_named_library(self): - if LXML_PRESENT: - assert registry.lookup("lxml", "xml") == LXMLTreeBuilderForXML - assert registry.lookup("lxml", "html") == LXMLTreeBuilder - if HTML5LIB_PRESENT: - assert registry.lookup("html5lib") == HTML5TreeBuilder - - assert registry.lookup("html.parser") == HTMLParserTreeBuilder - - def test_beautifulsoup_constructor_does_lookup(self): - with warnings.catch_warnings(record=True): - # This will create a warning about not explicitly - # specifying a parser, but we'll ignore it. - - # You can pass in a string. - BeautifulSoup("", features="html") - # Or a list of strings. - BeautifulSoup("", features=["html", "fast"]) - pass - - # You'll get an exception if BS can't find an appropriate - # builder. - with pytest.raises(ValueError): - BeautifulSoup("", features="no-such-feature") - - -class TestRegistry(object): - """Test the TreeBuilderRegistry class in general.""" - - def setup_method(self): - self.registry = TreeBuilderRegistry() - - def builder_for_features(self, *feature_list: str) -> Type[TreeBuilder]: - cls = type( - "Builder_" + "_".join(feature_list), (object,), {"features": feature_list} - ) - - self.registry.register(cls) - return cls - - def test_register_with_no_features(self): - builder = self.builder_for_features() - - # Since the builder advertises no features, you can't find it - # by looking up features. - assert self.registry.lookup("foo") is None - - # But you can find it by doing a lookup with no features, if - # this happens to be the only registered builder. - assert self.registry.lookup() == builder - - def test_register_with_features_makes_lookup_succeed(self): - builder = self.builder_for_features("foo", "bar") - assert self.registry.lookup("foo") is builder - assert self.registry.lookup("bar") is builder - - def test_lookup_fails_when_no_builder_implements_feature(self): - assert self.registry.lookup("baz") is None - - def test_lookup_gets_most_recent_registration_when_no_feature_specified(self): - self.builder_for_features("foo") - builder2 = self.builder_for_features("bar") - assert self.registry.lookup() == builder2 - - def test_lookup_fails_when_no_tree_builders_registered(self): - assert self.registry.lookup() is None - - def test_lookup_gets_most_recent_builder_supporting_all_features(self): - self.builder_for_features("foo") - self.builder_for_features("bar") - has_both_early = self.builder_for_features("foo", "bar", "baz") - has_both_late = self.builder_for_features("foo", "bar", "quux") - self.builder_for_features("bar") - self.builder_for_features("foo") - - # There are two builders featuring 'foo' and 'bar', but - # the one that also features 'quux' was registered later. - assert self.registry.lookup("foo", "bar") == has_both_late - - # There is only one builder featuring 'foo', 'bar', and 'baz'. - assert self.registry.lookup("foo", "bar", "baz") == has_both_early - - def test_lookup_fails_when_cannot_reconcile_requested_features(self): - self.builder_for_features("foo", "bar") - self.builder_for_features("foo", "baz") - assert self.registry.lookup("bar", "baz") is None diff --git a/.venv/Lib/site-packages/bs4/tests/test_css.py b/.venv/Lib/site-packages/bs4/tests/test_css.py deleted file mode 100644 index b1c4237..0000000 --- a/.venv/Lib/site-packages/bs4/tests/test_css.py +++ /dev/null @@ -1,536 +0,0 @@ -import pytest -import types - -from bs4 import ( - BeautifulSoup, - ResultSet, -) - -from typing import ( - Any, - List, - Tuple, - Type, -) - -from packaging.version import Version - -from . import ( - SoupTest, - SOUP_SIEVE_PRESENT, -) - -SOUPSIEVE_EXCEPTION_ON_UNSUPPORTED_PSEUDOCLASS: Type[Exception] -if SOUP_SIEVE_PRESENT: - from soupsieve import __version__, SelectorSyntaxError - - # Some behavior changes in soupsieve 2.6 that affects one of our - # tests. For the test to run under all versions of Python - # supported by Beautiful Soup (which includes versions of Python - # not supported by soupsieve 2.6) we need to check both behaviors. - SOUPSIEVE_EXCEPTION_ON_UNSUPPORTED_PSEUDOCLASS = SelectorSyntaxError - if Version(__version__) < Version("2.6"): - SOUPSIEVE_EXCEPTION_ON_UNSUPPORTED_PSEUDOCLASS = NotImplementedError - - -@pytest.mark.skipif(not SOUP_SIEVE_PRESENT, reason="Soup Sieve not installed") -class TestCSSSelectors(SoupTest): - """Test basic CSS selector functionality. - - This functionality is implemented in soupsieve, which has a much - more comprehensive test suite, so this is basically an extra check - that soupsieve works as expected. - """ - - HTML = """ - - - -The title - - - -Hello there. -
-
-

An H1

-

Some text

-

Some more text

-

An H2

-

Another

-Bob -

Another H2

-me - -span1a1 -span1a2 test - -span2a1 - - - -
- -
- - - - - - - - -

English

-

English UK

-

English US

-

French

-
- - -""" - - def setup_method(self): - self._soup = BeautifulSoup(self.HTML, "html.parser") - - def assert_css_selects( - self, selector: str, expected_ids: List[str], **kwargs: Any - ) -> None: - results = self._soup.select(selector, **kwargs) - assert isinstance(results, ResultSet) - el_ids = [el["id"] for el in results] - el_ids.sort() - expected_ids.sort() - assert expected_ids == el_ids, "Selector %s, expected [%s], got [%s]" % ( - selector, - ", ".join(expected_ids), - ", ".join(el_ids), - ) - - assertSelect = assert_css_selects - - def assert_css_select_multiple(self, *tests: Tuple[str, List[str]]): - for selector, expected_ids in tests: - self.assert_css_selects(selector, expected_ids) - - def test_precompiled(self): - sel = self._soup.css.compile("div") - - els = self._soup.select(sel) - assert len(els) == 4 - for div in els: - assert div.name == "div" - - el = self._soup.select_one(sel) - assert "main" == el["id"] - - def test_one_tag_one(self): - els = self._soup.select("title") - assert len(els) == 1 - assert els[0].name == "title" - assert els[0].contents == ["The title"] - - def test_one_tag_many(self): - els = self._soup.select("div") - assert len(els) == 4 - for div in els: - assert div.name == "div" - - el = self._soup.select_one("div") - assert "main" == el["id"] - - def test_select_one_returns_none_if_no_match(self): - match = self._soup.select_one("nonexistenttag") - assert None is match - - def test_tag_in_tag_one(self): - self.assert_css_selects("div div", ["inner", "data1"]) - - def test_tag_in_tag_many(self): - for selector in ("html div", "html body div", "body div"): - self.assert_css_selects(selector, ["data1", "main", "inner", "footer"]) - - def test_limit(self): - self.assert_css_selects("html div", ["main"], limit=1) - self.assert_css_selects("html body div", ["inner", "main"], limit=2) - self.assert_css_selects( - "body div", ["data1", "main", "inner", "footer"], limit=10 - ) - - def test_tag_no_match(self): - assert len(self._soup.select("del")) == 0 - - def test_invalid_tag(self): - with pytest.raises(SelectorSyntaxError): - self._soup.select("tag%t") - - def test_select_dashed_tag_ids(self): - self.assert_css_selects("custom-dashed-tag", ["dash1", "dash2"]) - - def test_select_dashed_by_id(self): - dashed = self._soup.select('custom-dashed-tag[id="dash2"]') - assert dashed[0].name == "custom-dashed-tag" - assert dashed[0]["id"] == "dash2" - - def test_dashed_tag_text(self): - assert self._soup.select("body > custom-dashed-tag")[0].text == "Hello there." - - def test_select_dashed_matches_find_all(self): - assert self._soup.select("custom-dashed-tag") == self._soup.find_all( - "custom-dashed-tag" - ) - - def test_header_tags(self): - self.assert_css_select_multiple( - ("h1", ["header1"]), - ("h2", ["header2", "header3"]), - ) - - def test_class_one(self): - for selector in (".onep", "p.onep", "html p.onep"): - els = self._soup.select(selector) - assert len(els) == 1 - assert els[0].name == "p" - assert els[0]["class"] == ["onep"] - - def test_class_mismatched_tag(self): - els = self._soup.select("div.onep") - assert len(els) == 0 - - def test_one_id(self): - for selector in ("div#inner", "#inner", "div div#inner"): - self.assert_css_selects(selector, ["inner"]) - - def test_bad_id(self): - els = self._soup.select("#doesnotexist") - assert len(els) == 0 - - def test_items_in_id(self): - els = self._soup.select("div#inner p") - assert len(els) == 3 - for el in els: - assert el.name == "p" - assert els[1]["class"] == ["onep"] - assert not els[0].has_attr("class") - - def test_a_bunch_of_emptys(self): - for selector in ("div#main del", "div#main div.oops", "div div#main"): - assert len(self._soup.select(selector)) == 0 - - def test_multi_class_support(self): - for selector in ( - ".class1", - "p.class1", - ".class2", - "p.class2", - ".class3", - "p.class3", - "html p.class2", - "div#inner .class2", - ): - self.assert_css_selects(selector, ["pmulti"]) - - def test_multi_class_selection(self): - for selector in (".class1.class3", ".class3.class2", ".class1.class2.class3"): - self.assert_css_selects(selector, ["pmulti"]) - - def test_child_selector(self): - self.assert_css_selects(".s1 > a", ["s1a1", "s1a2"]) - self.assert_css_selects(".s1 > a span", ["s1a2s1"]) - - def test_child_selector_id(self): - self.assert_css_selects(".s1 > a#s1a2 span", ["s1a2s1"]) - - def test_attribute_equals(self): - self.assert_css_select_multiple( - ('p[class="onep"]', ["p1"]), - ('p[id="p1"]', ["p1"]), - ('[class="onep"]', ["p1"]), - ('[id="p1"]', ["p1"]), - ('link[rel="stylesheet"]', ["l1"]), - ('link[type="text/css"]', ["l1"]), - ('link[href="blah.css"]', ["l1"]), - ('link[href="no-blah.css"]', []), - ('[rel="stylesheet"]', ["l1"]), - ('[type="text/css"]', ["l1"]), - ('[href="blah.css"]', ["l1"]), - ('[href="no-blah.css"]', []), - ('p[href="no-blah.css"]', []), - ('[href="no-blah.css"]', []), - ) - - def test_attribute_tilde(self): - self.assert_css_select_multiple( - ('p[class~="class1"]', ["pmulti"]), - ('p[class~="class2"]', ["pmulti"]), - ('p[class~="class3"]', ["pmulti"]), - ('[class~="class1"]', ["pmulti"]), - ('[class~="class2"]', ["pmulti"]), - ('[class~="class3"]', ["pmulti"]), - ('a[rel~="friend"]', ["bob"]), - ('a[rel~="met"]', ["bob"]), - ('[rel~="friend"]', ["bob"]), - ('[rel~="met"]', ["bob"]), - ) - - def test_attribute_startswith(self): - self.assert_css_select_multiple( - ('[rel^="style"]', ["l1"]), - ('link[rel^="style"]', ["l1"]), - ('notlink[rel^="notstyle"]', []), - ('[rel^="notstyle"]', []), - ('link[rel^="notstyle"]', []), - ('link[href^="bla"]', ["l1"]), - ('a[href^="http://"]', ["bob", "me"]), - ('[href^="http://"]', ["bob", "me"]), - ('[id^="p"]', ["pmulti", "p1"]), - ('[id^="m"]', ["me", "main"]), - ('div[id^="m"]', ["main"]), - ('a[id^="m"]', ["me"]), - ('div[data-tag^="dashed"]', ["data1"]), - ) - - def test_attribute_endswith(self): - self.assert_css_select_multiple( - ('[href$=".css"]', ["l1"]), - ('link[href$=".css"]', ["l1"]), - ('link[id$="1"]', ["l1"]), - ( - '[id$="1"]', - ["data1", "l1", "p1", "header1", "s1a1", "s2a1", "s1a2s1", "dash1"], - ), - ('div[id$="1"]', ["data1"]), - ('[id$="noending"]', []), - ) - - def test_attribute_contains(self): - self.assert_css_select_multiple( - # From test_attribute_startswith - ('[rel*="style"]', ["l1"]), - ('link[rel*="style"]', ["l1"]), - ('notlink[rel*="notstyle"]', []), - ('[rel*="notstyle"]', []), - ('link[rel*="notstyle"]', []), - ('link[href*="bla"]', ["l1"]), - ('[href*="http://"]', ["bob", "me"]), - ('[id*="p"]', ["pmulti", "p1"]), - ('div[id*="m"]', ["main"]), - ('a[id*="m"]', ["me"]), - # From test_attribute_endswith - ('[href*=".css"]', ["l1"]), - ('link[href*=".css"]', ["l1"]), - ('link[id*="1"]', ["l1"]), - ( - '[id*="1"]', - [ - "data1", - "l1", - "p1", - "header1", - "s1a1", - "s1a2", - "s2a1", - "s1a2s1", - "dash1", - ], - ), - ('div[id*="1"]', ["data1"]), - ('[id*="noending"]', []), - # New for this test - ('[href*="."]', ["bob", "me", "l1"]), - ('a[href*="."]', ["bob", "me"]), - ('link[href*="."]', ["l1"]), - ('div[id*="n"]', ["main", "inner"]), - ('div[id*="nn"]', ["inner"]), - ('div[data-tag*="edval"]', ["data1"]), - ) - - def test_attribute_exact_or_hypen(self): - self.assert_css_select_multiple( - ('p[lang|="en"]', ["lang-en", "lang-en-gb", "lang-en-us"]), - ('[lang|="en"]', ["lang-en", "lang-en-gb", "lang-en-us"]), - ('p[lang|="fr"]', ["lang-fr"]), - ('p[lang|="gb"]', []), - ) - - def test_attribute_exists(self): - self.assert_css_select_multiple( - ("[rel]", ["l1", "bob", "me"]), - ("link[rel]", ["l1"]), - ("a[rel]", ["bob", "me"]), - ("[lang]", ["lang-en", "lang-en-gb", "lang-en-us", "lang-fr"]), - ("p[class]", ["p1", "pmulti"]), - ("[blah]", []), - ("p[blah]", []), - ("div[data-tag]", ["data1"]), - ) - - def test_quoted_space_in_selector_name(self): - html = """
nope
-
yes
- """ - soup = BeautifulSoup(html, "html.parser") - [chosen] = soup.select('div[style="display: right"]') - assert "yes" == chosen.string - - def test_unsupported_pseudoclass(self): - with pytest.raises(SOUPSIEVE_EXCEPTION_ON_UNSUPPORTED_PSEUDOCLASS): - self._soup.select("a:no-such-pseudoclass") - - with pytest.raises(SelectorSyntaxError): - self._soup.select("a:nth-of-type(a)") - - def test_nth_of_type(self): - # Try to select first paragraph - els = self._soup.select("div#inner p:nth-of-type(1)") - assert len(els) == 1 - assert els[0].string == "Some text" - - # Try to select third paragraph - els = self._soup.select("div#inner p:nth-of-type(3)") - assert len(els) == 1 - assert els[0].string == "Another" - - # Try to select (non-existent!) fourth paragraph - els = self._soup.select("div#inner p:nth-of-type(4)") - assert len(els) == 0 - - # Zero will select no tags. - els = self._soup.select("div p:nth-of-type(0)") - assert len(els) == 0 - - def test_nth_of_type_direct_descendant(self): - els = self._soup.select("div#inner > p:nth-of-type(1)") - assert len(els) == 1 - assert els[0].string == "Some text" - - def test_id_child_selector_nth_of_type(self): - self.assert_css_selects("#inner > p:nth-of-type(2)", ["p1"]) - - def test_select_on_element(self): - # Other tests operate on the tree; this operates on an element - # within the tree. - inner = self._soup.find("div", id="main") - selected = inner.select("div") - # The
tag was selected. The