python 和 lxml 的空格问题
我正在尝试使用 python 和 lxml 抓取这个网站。 它在我的本地计算机上工作得很好,但是当我尝试将它部署在我的服务器上并运行脚本时,我遇到了空格问题。 URL:http://www.samsungapps.com/topApps/topAppsDetail .as?productId=G00000467050&listYN=Y
html中的问题部分:
<tr>
<th>Version</th>
<td>
1.0.0 (14.02.2011)
</td>
</tr>
我认为这是我的服务器配置问题。 有人知道我错过了什么吗?
提前致谢
编辑:
html = seite.read()
seite.close()
tree = etree.parse(StringIO.StringIO(html), parser)
xpath = "//div[contains(@class,'detail-view')]/h4/text()"
name = tree.xpath(xpath)
xpath = "//div[contains(@class,'detail-view')]/table/tbody/tr[2]/td/text()"
cat = tree.xpath(xpath)
xpath = "//div[contains(@class,'detail-view')]/table/tbody/tr[3]/td/text()"
typ = tree.xpath(xpath)
xpath = "//div[contains(@class,'detail-view')]/table/tbody/tr[4]/td/text()"
version = tree.xpath(xpath)
print name[0].encode("utf-8")
print cat[0].encode("utf-8")
print typ[0].encode("utf-8")
print version[0].encode("utf-8")
I'm trying do scrape this website with python and lxml.
Its working greate on my local machine, but when i try to deploy it on my server and run the script i got problems with whitespaces.
URL: http://www.samsungapps.com/topApps/topAppsDetail.as?productId=G00000467050&listYN=Y
Problem part in html:
<tr>
<th>Version</th>
<td>
1.0.0 (14.02.2011)
</td>
</tr>
I think it's a problem of configuration of my server.
Does anyone got an idea what i missed?
Thanks in advance
Edit:
html = seite.read()
seite.close()
tree = etree.parse(StringIO.StringIO(html), parser)
xpath = "//div[contains(@class,'detail-view')]/h4/text()"
name = tree.xpath(xpath)
xpath = "//div[contains(@class,'detail-view')]/table/tbody/tr[2]/td/text()"
cat = tree.xpath(xpath)
xpath = "//div[contains(@class,'detail-view')]/table/tbody/tr[3]/td/text()"
typ = tree.xpath(xpath)
xpath = "//div[contains(@class,'detail-view')]/table/tbody/tr[4]/td/text()"
version = tree.xpath(xpath)
print name[0].encode("utf-8")
print cat[0].encode("utf-8")
print typ[0].encode("utf-8")
print version[0].encode("utf-8")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
.strip()
对我有用测试
Adding
.strip()
works for meTests