python - Urllib 返回 html 但没有结束段落标记

标签 python html python-3.x web-scraping urllib

我正在抓取总统辩论记录。我注意到,当我的抓取工具拉取 html 元素时,它永远不会拉取段落结束标记 ( </p> )。

例如

在浏览器中检查源 from Chrome's View > Developer > View source

url_to_scrape = 'http://www.presidency.ucsb.edu/ws/index.php?pid=119039'
req = urllib.request.Request(url_to_scrape)
resp = urllib.request.urlopen(req)
resp.read()

Python results

我认为发生了以下两件事之一:

  1. urllib 以某种方式删除了结束标签(仅适用于段落,其余都很好)
  2. 原始源代码不包含结束标记,浏览器正在填充它们。

如何找出它是哪一个,然后进行更正?

最佳答案

您可以检查 Chrome 收到的实际数据包吗?在某些情况下,Chrome 会检测并纠正像这样的小遗漏,以便显示页面,即使它们不在数据包中。我的猜测是 Chrome 修复了这个问题,但实际来源很糟糕。

关于python - Urllib 返回 html 但没有结束段落标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52544562/

相关文章:

python - 如何在图中的 x 轴上添加年份?

python - 在 python 脚本中使用 bash 命令时出现问题

javascript - React 模型粘性 header

html - 如何防止图片框外的描述文字溢出?

javascript - FadeOut 结束然后做点什么

python - 使用列表循环将变量添加到元组

python - 覆盖 fastAPI 的 HTTPException 响应主体

python - 如何使用 python-gitlab 访问 gitlab api?

python - 使用 oauth 将 GAE python 应用程序连接到 google 的 drive/docs/spreadsheet

python-3.x - Pandas DataFrame.empty() 给出 TypeError : 'bool' object is not callable