- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试解析一个网站,稍后我将在我的 Django 项目中使用它。为此,我使用了 urllib2 和 BeautifulSoup4。然而,我得不到我想要的。 BeautifulSoup 对象的输出很奇怪。我尝试了不同的页面,它起作用了(输出是正常的)。我认为这是因为页面。然后,当我的 friend 尝试做同样的事情时,他得到了正常的输出。我无法找出问题所在。
这是 website我要解析了。
这是命令“soup.prettify()”后奇怪输出的示例:
t d B G C O L O R = " # 9 9 0 4 0 4 " w i d t h = " 3 " > i m g S R C = " 1 p . g i f " A L T B O R D E R = " 0 " h e i g h t = " 1 " w i d t h = " 3 " > / t d > \n / t r > \n t r > \n t d c o l s p a n = " 3 " B G C O L O R = " # 9 9 0 4 0 4 " w i d t h = " 6 0 0 " h e i g h t = " 3 " > i m g s r c = " 1 p . g i f " w i d t h = " 6 0 0 " \n h e i g h t = " 1 " > / t d > \n / t r > \n / t a b l e > \n / c e n t e r > / d i v > \n \n p > &n b s p ; &n b s p ; &n b s p ; &n b s p ; / p > \n / b o d y > \n / h t m l >\n </p>\n </body>\n</html>'
最佳答案
这是一个确实对我有用的最小示例,包括您遇到问题的 html 片段。没有你的代码很难说,但我猜你在某处做了类似 ' '.join(A.split())
的事情。
import urllib2, bs4
url = "http://kafemud.bilkent.edu.tr/monu_tr.html"
req = urllib2.urlopen(url)
raw = req.read()
soup = bs4.BeautifulSoup(raw)
print soup.prettify().encode('utf-8')
给予:
....
<td bgcolor="#990404" width="3">
<img alt="" border="0" src="1p.gif" width="3"/>
</td>
<td bgcolor="#FFFFFF" valign="TOP">
<div align="left">
<table align="left" border="0" cellpadding="10" cellspacing="0" valign="TOP" width="594">
<tr>
<td align="left" valign="top">
<table align="left" border="0" cellpadding="0" cellspacing="0" class="icerik" width="574">
....
关于python - BeautifulSoup soup.prettify() 给出奇怪的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20906416/
我似乎无法让 google prettify 使用基本的 XML:任何人都可以使用它,或者可以看到我做错了什么:这是我的代码: XML Output 如有任何帮助,我们
我想使用自定义 css/js。我已将这些移动到服务器。但是 drupal 页面以一个部分开头。如何将自定义 css/js 添加到我的 drupal 网站页面。我有管理员,只需要知道如何将其包含在页面上
我正在使用 Prettify 进行语法高亮显示,但它不适用于动态生成的代码。 我有一个表单,提交后会生成代码并在 中显示(无需刷新) , 但美化不适用于此代码,是否有任何解决方法? 非常感谢! 最佳
我在任何地方都找不到这个,我发誓我曾经能够非常简单地进行窥探。谁能帮我?谢谢。我会很感激。还有美化 支持批处理? 最佳答案 您可以在 FAQ 中找到表格, 在标题下 For which languag
有没有办法让 Swagger 自己美化 JSON,而不需要被调用的库输出漂亮的 JSON?我似乎找不到关于这个主题的任何内容。 最佳答案 您问题的答案在 projects's GitHub 上. 您可
我有一个 div,我在其中根据 AJAX 请求的结果动态加载一段代码。然后我想使用 prettify 对其进行格式化。它有效,但它太慢了。我使用的代码如下: var jqxhr = $.get(fil
我一直在玩 Prettify,我很快就让它工作了。但是,当我尝试更改 css 文件中的字体时,我似乎无法在浏览器中看到任何更改。我正在使用 Silver Stripe 作为 CMS。在网站的 CSS
我仅在 时加载脚本存在。我发现要启动Prettify,您需要使用prettyPrint(); . 但是,在不加载脚本的页面上,我收到 Javascript 错误。有没有办法测试 Prettify 是
因此我们最近将我们的浏览器支持政策更改为 IE 8/9、Firefox、Chrome 和 Windows 7 上的 Safari,所有这些都支持 box-sizing: border-box; 以某种
我正在使用 BeautifulSoup 来解析 html 文章。我使用了一些函数来清除html,所以我可以只保留主要文章。 此外,我想将 Soup 输出保存到一个文件中。我得到的错误如下: soup
我收到一个 Unicode 错误:UnicodeEncodeError: 'charmap' codec can't encode character u'\xa9' in position 822:
有没有办法为 .prettify() 函数定义自定义缩进宽度?从我可以从它的来源获得的信息 - def prettify(self, encoding=None, formatter="minimal
为了解析网站的html代码,我决定使用BeautifulSoup类(class)和 prettify()方法。我写了下面的代码。 import requests import bs4 response
我正在使用Isotope与哈希历史记录。它工作得很好,但我对这个 URL 不满意 - 我想简化和清理它。 当前使用: var href = $this.attr('href').replace( /^
我试图在 matplotlib 中模拟一个三层饼图,但对其美观不满意。 具体来说,我似乎无法使三个级别(或 donut )更加独特。另外,我想理想地将标签显示为图例,而不是它们当前的显示方式。最后,如
有 a set of "themes" for prettify.js . 我如何实际使用它们?我要吗 到选定的“主题”.css文件而不是 prettify.css文件或我做任何其他事情吗?流程是什么
我正在尝试从 Wine 网站获取一些数据。 但我无法评估数据,并且有一条使用违规消息。 网址:https://www.wine-searcher.com/find/drc/2013 prettify(
我目前正在寻找一种在我的网站中实现美化以允许在页面内容中发布代码片段的方法。 问题:我正在使用 Redactor WYSIWYG,这在编辑器中引起了一些问题(在编辑器中美化代码块的样式,将样式化的 h
目前我的代码在 for 循环中的 int count_simd(char *arr, int len, char key) { int count = 0; __m128i sixt
我想更改颜色,甚至完全禁用我在 blog@blogger 上使用的 google prettify 中的交替背景颜色。 我当前的 CSS 是 Doxy 主题,但有此更改: /* Specify cla
我是一名优秀的程序员,十分优秀!