Ik heb BeautifulSoup geïnstalleerd met easy_install en probeer het volgende script uit te voeren
from BeautifulSoup import BeautifulSoup
import re
doc = ['<html><head><title>Page title</title></head>',
'<body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
'<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
'</html>']
soup = BeautifulSoup(''.join(doc))
print soup.prettify()
Maar ik weet niet zeker waarom dit gebeurt
Traceback (most recent call last):
File "C:\Python27\reading and writing xml file from web1.py", line 49, in <module>
from BeautifulSoup import BeautifulSoup
ImportError: No module named BeautifulSoup
Kunt u alstublieft helpen.
Bedankt
Antwoord 1, autoriteit 100%
Probeer deze from bs4 import BeautifulSoup
Dit kan een probleem zijn met Beautiful Soup, versie 4, en de bètadagen. Ik las dit net van de homepage.
Antwoord 2, autoriteit 9%
Op Ubuntu 14.04 heb ik het geïnstalleerd vanaf apt-get en het werkte prima:
sudo apt-get install python-beautifulsoup
Doe dan gewoon:
from BeautifulSoup import BeautifulSoup
Antwoord 3, autoriteit 4%
Probeer dit, de mijne werkte op deze manier. Om gegevens van een tag te krijgen, vervangt u de “a” door de gewenste tag.
from bs4 import BeautifulSoup as bs
import urllib
url="http://currentaffairs.gktoday.in/month/current-affairs-january-2015"
soup = bs(urllib.urlopen(url))
for link in soup.findAll('a'):
print link.string
Antwoord 4, Autoriteit 3%
U kunt BS4 importeren in plaats van Mooi.
Aangezien BS4 een ingebouwde module is, is er geen aanvullende installatie vereist.
from bs4 import BeautifulSoup
import re
doc = ['<html><head><title>Page title</title></head>',
'<body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
'<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
'</html>']
soup = BeautifulSoup(''.join(doc))
print soup.prettify()
Als u wilt aanvragen, met behulp van aanvragenmodule.
verzoek gebruikt urllib
, requests
MODULES.
Maar ik persoonlijk aanbeveling met requests
module in plaats van urllib
Module installeren voor het gebruik van:
$ pip install requests
Hier is het gebruik van de aanvragenmodule:
import requests as rq
res = rq.get('http://www.example.com')
print(res.content)
print(res.status_code)
Antwoord 5
Als u zijn op deze manier hebt geïnstalleerd (als u dat niet bent, op deze manier installeert):
pip install beautifulsoup4
en als u deze code hebt gebruikt (als u dat niet, gebruikt u deze code):
from bs4 import BeautifulSoup
Als u Windows-systeem gebruikt, controleert u deze als er module is, kan de module van het pad zijn ingeslagen
Antwoord 6
Installeer eerst mooie soepversie 4.
Schrijfopdracht in het venster Terminal:
pip install beautifulsoup4
Importeer vervolgens de Beutifulsoup-bibliotheek
Antwoord 7
Als u twee versie van Python kreeg, kan mijn situatie misschien u helpen
Dit is mijn situatie
1- & GT; Mac OSX
2- & GT; Ik heb twee versie Python, (1) Systeem Standaard versie 2.7 (2) Handmatig geïnstalleerd versie 3.6
3- & GT; Ik heb de Beautifulsoup4 geïnstalleerd met sudo pip install beautifulsoup4
4- & GT; Ik voer het Python-bestand uit met python3 /XXX/XX/XX.py
Dus deze situatie 3 en 4 zijn het sleutelgedeelte, ik heb M Bewind PIMSOUP4 geïnstalleerd met “PIP”, maar deze module is geïnstalleerd voor Python Verison 2.7, en ik voer het Python-bestand uit met “Python3”. Dus u moet MEWERSOUP4 voor de Python 3.6 installeren;
Met de sudo pip3 install beautifulsoup4
U kunt de module installeren voor de Python 3.6
Antwoord 8
Ik had hetzelfde probleem met Eclipse op Windows 10.
Ik heb het geïnstalleerd, zoals het Windows-opdrachtvenster (CMD) met:
C:\Users\NAMEOFUSER\AppData\Local\Programs\Python\beautifulsoup4-4.8.2\setup.py install
Beautifulsoup was als volgt in mijn python directory:
C:\Users\NAMEOFUSE\AppData\Local\Programs\Python\Python38\Lib\site-packages\beautifulsoup4-4.8.2-py3.8.egg
Nadat u de BS4- en EGE-info-mappen handmatig is ingeschakeld in de map Site-pakketten begon alles te werken, ook het voorbeeld:
from bs4 import BeautifulSoup
html = """
<html>
<body>
<p> Ich bin ein Absatz!</p>
</body>
</html>
"""
print(html)
soup = BeautifulSoup(html, 'html.parser')
print(soup.find_all("p"))