ImportError : BeautifulSoup이라는 모듈이 없습니다.
easy_install을 사용하여 BeautifulSoup을 설치하고 다음 스크립트를 실행하려고합니다.
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()
하지만 왜 이런 일이 일어나는지 잘 모르겠습니다.
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
도와 주 시겠어요? 감사
이 시도 from bs4 import BeautifulSoup
뷰티플 수프 버전 4, 베타 버전의 문제 일 수 있습니다. 방금 홈페이지에서 읽었습니다.
Ubuntu 14.04에서는 apt-get에서 설치했으며 제대로 작동했습니다.
sudo apt-get install python-beautifulsoup
그런 다음 다음을 수행하십시오.
from BeautifulSoup import BeautifulSoup
이것을 시도해보십시오. 태그의 데이터를 얻으려면 "a"를 원하는 태그로 바꾸십시오.
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
BeautifulSoup 대신 bs4를 가져올 수 있습니다. bs4는 내장 모듈이므로 추가 설치가 필요하지 않습니다.
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()
요청하려면 requests 모듈을 사용하십시오. 요청이 urllib
, requests
모듈을 사용 하고 있습니다. 하지만 개인적으로 requests
대신 모듈을 사용하는 것이 좋습니다urllib
사용을위한 모듈 설치 :
$ pip install requests
요청 모듈을 사용하는 방법은 다음과 같습니다.
import requests as rq
res = rq.get('http://www.example.com')
print(res.content)
print(res.status_code)
if you got two version of python, maybe my situation could help you
this is my situation
1-> mac osx
2-> i have two version python , (1) system default version 2.7 (2) manually installed version 3.6
3-> i have install the beautifulsoup4 with sudo pip install beautifulsoup4
4-> i run the python file with python3 /XXX/XX/XX.py
so this situation 3 and 4 are the key part, i have install beautifulsoup4 with "pip" but this module was installed for python verison 2.7, and i run the python file with "python3". so you should install beautifulsoup4 for the python 3.6;
with the sudo pip3 install beautifulsoup4
you can install the module for the python 3.6
참고URL : https://stackoverflow.com/questions/5663980/importerror-no-module-named-beautifulsoup
'IT TIP' 카테고리의 다른 글
파이썬에서 2 개의 목록 빼기 (0) | 2020.10.17 |
---|---|
0/1 대신 부울 유형에 대해 Y / N을 저장하도록 최대 절전 모드 (JPA 사용)를 구성합니다. (0) | 2020.10.17 |
동적으로 양식 생성 및 제출 (0) | 2020.10.17 |
조각에서 활동 시작 (0) | 2020.10.17 |
32 비트 정수가 오버플로되면 64 비트 길이 대신 40 비트 구조를 사용할 수 있습니까? (0) | 2020.10.17 |