我正试图从jb hifi中提取间谍信息,以下是我所做的:
from BeautifulSoup import BeautifulSoup
import urllib2
import re
url="http://www.jbhifionline.com.au/support.aspx?post=1&results=10&source=all&bnSearch=Go!&q=ipod&submit=Go"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
Item0=soup.findAll('td',{'class':'check_title'})[0]
print (Item0.renderContents())
输出为:
Apple iPod Classic 160GB (Black)Â
<span class="SKU">MC297ZP/A</span>
我想要的是:
Apple iPod Classic 160GB (Black)
我试着用re删除其他信息
print(Item0.renderContents()).replace{^<span:,""}
但没用
所以我的问题是如何删除无用的信息并获得“Apple ipod classic 160GB(黑色)”
不要使用
.renderContents()
;它充其量只是一个调试工具。你知道吗只要有第一个孩子:
BeautifulSoup似乎没有正确地猜出编码,因此不间断空格(U+00a0)以两个独立的字节而不是一个字节的形式出现。看来美女苏猜错了:
您可以使用响应头强制编码;此服务器设置了字符集:
fromEncoding
参数告诉BeautifulSoup使用UTF-8而不是拉丁语1,现在正确地剥离了非中断空间。你知道吗相关问题 更多 >
编程相关推荐