Python BeautifulSoup在服务器和笔记本电脑上提供不同的结果
我在服务器(Ubuntu14.04.2LTS)和笔记本电脑(Ubuntu15.04)上运行了一段代码,得到了不同的结果。 我正在使用相同的html文件构建汤(自己将其复制到服务器) 服务器打印:Python BeautifulSoup在服务器和笔记本电脑上提供不同的结果,python,python-2.7,beautifulsoup,Python,Python 2.7,Beautifulsoup,我在服务器(Ubuntu14.04.2LTS)和笔记本电脑(Ubuntu15.04)上运行了一段代码,得到了不同的结果。 我正在使用相同的html文件构建汤(自己将其复制到服务器) 服务器打印:2 而在本地打印:7 更多信息: 服务器: Python 2.7.6 第4.3.2条 pip 7.0.3 本地: Python 2.7.9 第4.3.2条 pip 1.5.6 我错过了什么?我还应该寻找什么呢?我的服务器没有安装lxml,而lxml 3.4.4是在本地安装的。在服务器上安装它解决了
2
而在本地打印:7
更多信息:
服务器:
- Python 2.7.6
- 第4.3.2条
- pip 7.0.3
- Python 2.7.9
- 第4.3.2条
- pip 1.5.6
我错过了什么?我还应该寻找什么呢?我的服务器没有安装lxml,而lxml 3.4.4是在本地安装的。在服务器上安装它解决了问题您是否在其中一个上安装了
lxml
?bs4.BeautifulSoup(temp,'html.parser')
是否使数字合适?@MartijnPieters谢谢,这就解释了问题,我在服务器上没有lxml。
temp = open('temp.html', 'r')
soup = bs4.BeautifulSoup(temp.read())
table = soup.find('table')
if not table:
return []
rows = table.find_all('tr')
print len(rows)