菜鸟学python,模块使用

nishuihanliu 2016-06-10 02:57:55

from urllib import request
import AdvancedHTMLParser

with request.urlopen('https://www.python.org/events/python-events/') as f:
html=f.read().decode('utf-8')
print(html)
parser=AdvancedHTMLParser.AdvancedHTMLParser()
parser.parseStr(html)
event=parser.getElementsByTagName('time')
# print(event[0][0])
location=parser.getElementsByClassName('event-location')
for item in event :
print(item.innerHTML)
for loc in location:
print(loc.innerHTML)


这是爬取的时间和地点,一一对应,请问如何能将红线部分去除掉?
...全文
155 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
just59277 2016-06-15
  • 打赏
  • 举报
回复
应该是去掉 < > 中的内容吧? 可以使用正则试试。
屎克螂 2016-06-12
  • 打赏
  • 举报
回复
最简单的替换 print "axxxa".replace("xxx", "")

37,737

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧