作者ansi54 (笑笑生)
看板Python
标题[问题] 网路爬虫後的资料分析
时间Wed Dec 2 14:35:50 2015
大家好
小弟近来自学python的网路爬虫
抓取网页的html档後用beautifulsoup资料分析
我的目的在於要抓取关键字搜索後的资料(一页有50笔)
目前发现一个问题无法解决(也google不到)
因为我要抓的网页资料在原始码上的编排有做手脚
我要抓的title它有些是编排为: "标题"
有些是:"标题
"
因为这个双引号位置的关系,使得我抓出来的资料编排就不一致
请问各位先进 我要如何修改我的程式才能让我抓出来的资料编排一致?
谢谢
小弟的程式如下:
for item in range (0, 50):
title = soup.findAll('a',{'class':'t'})[item].get_text().strip()
date_t = soup.findAll('span',{'class':'date'})[item].get_text()
print date_t,".",title
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.109.197.38
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1449038152.A.43F.html
1F:推 Slimlife: Did you try regexp already? 12/02 20:14
2F:→ ansi54: not yet, but I'll try it. THX. 12/03 09:12
3F:→ Ziom: 有时某些空格用strip()也消不掉 可以试"".join(s.split()) 12/03 22:50
4F:→ Ziom: 其中s是你要拆解的string 12/03 22:50
5F:→ ansi54: 谢谢z大 我会试试看的 感谢 12/04 09:05