2

私はbeautifulSoupを一般的なPythonパスに1つ、virtualenvにもう1つインストールしました

beautifulsoup4  - 4.1.3        - active  # in general Python installation

beautifulsoup4  - 4.1.3        - active # in virtualenv path

両方の環境で次のコードを実行します

import urllib2
import unicodedata
from bs4 import BeautifulSoup
from collections import Counter
soup = BeautifulSoup(urllib2.urlopen('http://www.thehindu.com/news/cities/bangalore/aero-india-takes-off-on-february-6/article4329776.ece').fp)

一般的なPythonのインストールでは、それは私に与えます

>>> soup.select('.article-text .body')
[<p class="body"> It is that time when aviation buffs get ready to take off to the Air Force Station in Yelahanka here when the ninth edition of Aero India will be inaugurated by Defence Minister A.K. Antony on February 6.</p>, <p class="body">They can watch aerobatics by, among others, the Flying Bulls from the Czech Republic and Russian Knights — the Russian Air Force Aerobatic Team will complement Indian Air Force’s Sarang Aerobatic Team — at the biennial event that provides a platform for Indian and foreign vendors.</p>, <p class="body">However, IAF’s pride — the Surya Kiran Aerobatic Tea — which has performed to huge plaudits from the audience in the previous shows, will not be there for the country’s premier air show, a press release said.</p>, <p class="body">All exhibition space has been sold out and this edition is expected to see the participation of over 600 companies and 768 overseas delegations. </p>, <p class="body">The largest overseas participation is from the U.S. followed by Israel and Russia. The other major participants include France, the U.K., Germany and Belgium, Bulgaria, Italy, Ukraine, Australia, Belarus, Czech Republic, Japan, Norway, South Africa, Spain, Switzerland, Austria, Brazil, Canada, The Netherlands, Romania, Sweden, Singapore and the UAE.</p>, <p class="body">Organised by the Department of Defence Production, the five-day show aims at promoting products and services being offered by the Indian Defence industry in the international market.</p>]
>>> 

virtualenv環境では、何も表示されません

>>> soup.select('.article-text .body')  
[]

この問題の原因は何ですか? 仮想環境で修正するにはどうすればよいですか?

4

2 に答える 2

1

この問題の最も一般的な原因は、一方の環境にパーサー ライブラリがインストールされていて、もう一方の環境にはインストールされていないことです。それを確認してください。

于 2013-01-24T02:47:29.443 に答える
0

私はちょうどこの同じ問題に直面しました。私にとってうまくいった解決策は、パーサーを明示的に示すことでした。私の場合、これは次のとおりです。 soup = BeautifulSoup(markup, "html5lib")

于 2016-05-24T16:22:10.860 に答える