【问题标题】:Unable to read in the all the html of a webpage using Beautifulsoup无法使用 Beautifulsoup 读取网页的所有 html
【发布时间】:2020-09-24 08:37:32
【问题描述】:

我正在尝试使用 Beautifulsoup 从 SEC 提取 form-10k。不幸的是,以下代码并未显示所有 html。它从 html 中间的某个地方开始打印。但是,当应用于我尝试过的其他几个网页时,它工作正常。任何帮助都感激不尽。我对 python 编码很陌生,我希望能学到更多,因为它开始在我身上成长:)

import urllib.request, urllib.error
from bs4 import BeautifulSoup
import ssl

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

url = "https://www.sec.gov/Archives/edgar/data/920148/000092014820000011/lh10-k2019.htm"
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")
print(soup.prettify().encode("utf-8"))

【问题讨论】:

  • 无法复制,运行代码会打印整个页面。
  • 由于我的 pycharm 控制台空间不足,它没有打印整个 html。增加缓冲区大小后,它起作用了。

标签: python html parsing beautifulsoup html-parsing


【解决方案1】:

可能发生的情况是您的终端中没有足够的空间,所以您看到的只是其中的一部分,但实际上整个页面都在那里。我猜有效的页面要短得多。

【讨论】:

  • 感谢您的评论...有没有办法增加空间以便我可以看到整个 html?我将正则表达式应用于结果,但它产生了一个空列表。那是当我打印查看 html 并注意到它是从我要操作的部分下方打印的时候。
  • 取决于您使用的终端...如果是 Windows 命令提示符,您可以增加缓冲区大小 - 请参见此处:top-password.com/blog/…
  • 确实是空间问题。在充分增加控制台缓冲区大小后,它工作得很好。感谢您的帮助!
猜你喜欢
  • 2021-01-30
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 2018-08-27
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
相关资源
最近更新 更多