2

I have a beautifulSoup installed one in general Python path and another in virtualenv

beautifulsoup4  - 4.1.3        - active  # in general Python installation

and

beautifulsoup4  - 4.1.3        - active # in virtualenv path

I run the following code in both the environments

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)

In general Python installation, it gives me

>>> 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>]
>>> 

while in virtualenv environment, it shows nothing

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

What is causing this problem? How do I fix it in virtual env?

4

2 回答 2

1

此问题的最常见原因是一个环境安装了另一个缺少的解析器库。检查一下。

于 2013-01-24T02:47:29.443 回答
0

我刚刚遇到了同样的问题。对我有用的解决方案是明确指出解析器。就我而言,这是: soup = BeautifulSoup(markup, "html5lib")

于 2016-05-24T16:22:10.860 回答