Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python BeautifulSoup在服务器和笔记本电脑上提供不同的结果_Python_Python 2.7_Beautifulsoup - Fatal编程技术网

Python BeautifulSoup在服务器和笔记本电脑上提供不同的结果

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是在本地安装的。在服务器上安装它解决了

我在服务器(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是在本地安装的。在服务器上安装它解决了问题

您是否在其中一个上安装了
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)