In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what python installation methods, have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Installation method 1
① enters the python folder to execute instructions (provided that the pip directive is supported):
The code is as follows:
Pip3 install Beautifulsoup4
Python installation Bs4 and how to use it
Enter ② to complete the installation. If the following red box appears, the installation is successful.
If ③ verifies whether it can be run successfully, run cmd to execute it, and if no error is reported in the enter of the referenced module import bs4, it proves that the installation is complete and can be used normally:
Installation method 2
(various network restrictions like our company, the use of pip will be unable to install, has been looping in the retry):
① goes to the official website to download the package: Beautiful Soup official website download link
② decompresses the compressed package into the python file. Enter the command after entering the decompressed file (the previous python is indispensable):
The code is as follows:
Python setup.py install
Python installation Bs4 and how to use it
Enter python after the ③ has been run, and then enter help ('modules') to view all the modules currently owned by your python, as follows:
If the installation of ④ is completed as above, also check whether bs4 can be introduced normally. Enter: enter import bs4
Installation method 3
(if you are a python3 partner, you will find that the above two methods still do not work, and you cannot find the bs4 module by running help ('modules'). At this point, you need to use the following methods:
After ① also uses the second method above, copy the bs4 folder in the BeautifulSoup4 folder to lib under the python installation directory
② also cuts the Tools/scripts/2to3.py file under the python installation directory to lib under the python installation directory.
Cd to the lib directory in ③ cmd, and then run python 2to3.py bs4-w
Basic usage:
The code is as follows:
Import bs4from bs4 import BeautifulSouphtml_doc = "The Dormouse's storyThe Dormouse's story
Once upon a time there were three little sisters; and their names wereElsie,Lacie andTillie;and they lived at the bottom of a well.
...
"
Python installation Bs4 and how to use it
Create a BeautifulSoup object
The code is as follows:
Soup = BeautifulSoup (html_doc, "html.parser")
Python installation Bs4 and how to use it
Format document output
The code is as follows:
Soup.prettify ()
Python installation Bs4 and how to use it
Get title
The code is as follows:
Soup.title.text
Python installation Bs4 and how to use it
Get all tag attributes
Soup.a.attrs
Python installation Bs4 and how to use it
Determine whether it contains a tag attribute
The code is as follows:
Soup.a.has_attr ('class')
Python installation Bs4 and how to use it
Get the child elements of the tag
The code is as follows:
List (soup.p.children)
Python installation Bs4 and how to use it
The code is as follows:
List (soup.p.children) [0] .text
Python installation Bs4 and how to use it
Remove all labels
The code is as follows:
Soup.find_all ('a') for an in soup.find_all ('a'): print (a.attrs ['href'])
Python installation Bs4 and how to use it
Find the specified id
The code is as follows:
Soup.find (id='link3')
Python installation Bs4 and how to use it
Find out all the text.
The code is as follows:
Soup.get_text ()
This is the end of the simple example used.
Thank you for reading this article carefully. I hope the article "what are the installation methods of python" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.