Python virtualenv:同一版本的BeautifulSoup返回不同的结果

Python virtualenv:同一版本的BeautifulSoup返回不同的结果,python,beautifulsoup,Python,Beautifulsoup,我安装了一个beautifulSoup,一个安装在general Python path中,另一个安装在virtualenv中 beautifulsoup4 - 4.1.3 - active # in general Python installation 及 我在这两个环境中运行以下代码 import urllib2 import unicodedata from bs4 import BeautifulSoup from collections import Counte

我安装了一个beautifulSoup,一个安装在general Python path中,另一个安装在virtualenv中

beautifulsoup4  - 4.1.3        - active  # in general Python installation

我在这两个环境中运行以下代码

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

是什么导致了这个问题?如何在virtual env中修复此问题?

此问题最常见的原因是。检查一下。

我也遇到了同样的问题。对我有效的解决方案是显式指示解析器。就我而言,这是:
soup=BeautifulSoup(markup,“html5lib”)

如果代码相同,BS版本相同,我假设文件相同。。你需要找到不同之处。您没有为我们提供足够的信息来帮助您执行此操作。也许可以在您可以发布到此处的较小文件示例上尝试此操作,并向我们提供每个环境的规格。您是否检查了
urlib2.urlopen
调用是否返回相同的内容?@dm03514说得好!是的,我刚刚意识到你没有使用URL开启器,有些网站根据用户代理返回不同结构的HTML,每个环境可能使用不同的用户代理。好的方面,让我先检查一下
>>> 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>]
>>> 
>>> soup.select('.article-text .body')  
[]