【问题标题】:BeautifulSoup giving different results on server and laptopBeautifulSoup 在服务器和笔记本电脑上给出不同的结果
【发布时间】:2015-09-04 10:59:09
【问题描述】:

我在服务器(Ubuntu 14.04.2 LTS)和笔记本电脑(Ubuntu 15.04)上运行了一段代码,结果不同。 我正在使用相同的 html 文件构建汤(自己复制到服务器)

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)

服务器打印:2 而在本地打印:7

更多信息:

服务器:

  • Python 2.7.6
  • beautifulsoup4 4.3.2
  • 点 7.0.3

本地:

  • Python 2.7.9
  • beautifulsoup4 4.3.2
  • 点 1.5.6

我错过了什么?我还应该寻找什么?

【问题讨论】:

  • 您是否安装了lxml 而不是另一个? bs4.BeautifulSoup(temp, 'html.parser') 是否使数字适合?
  • @MartijnPieters 谢谢,这解释了问题,我在服务器上没有 lxml。

标签: python python-2.7 beautifulsoup


【解决方案1】:

我的服务器没有安装 lxml,而 lxml 3.4.4 是在本地安装的。在服务器上安装它解决了这个问题

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-09
    • 1970-01-01
    • 2017-04-21
    • 2013-09-12
    相关资源
    最近更新 更多