返回信息流#encoding=utf-8
from lxml import html
x = html.parse('http://www.mtime.com/hotest/')
titles = x.xpath('//dt/a/text()')
print "We got %s titles. Here are the first 5:" % len(titles)
for title in titles:
print title
上为老师爬时光网输出电影名称的源程序,输出结果如下:
We got 10 titles. Here are the first 5:
港囧 Lost In Hongkong(2015)
九层妖塔 Chronicles of the Ghostly Tribe(2015)
像素大战 Pixels(2015)
碟中谍5:神秘国度 Mission: Impossible - Rogue Nation(2015)
暗杀 Assassination(2015)
第三种爱情 The Third Way Of Love(2015)
小黄人大眼萌 Minions(2015)
解救吾先生 Saving Mr.Wu(2015)
魔镜 The Mirror(2015)
夏洛特烦恼 Goodbye Mr.Loser(2015)[/color]
我就稍微改动了下
#encoding=utf-8
from lxml import html
x = html.parse('http://bbs.byr.cn/#!board/Recommend?p=1')
titles = x.xpath("//td[@class='title_9']/a/text()|//td[@class='title_9 bg-odd']/a/text()")
print "We got %s titles:" % len(titles)
for title in titles:
print title
输出结果如下:
We got 0 titles:
在google的插件xpath里面
//td[@class='title_9']/a/text()|//td[@class='title_9 bg-odd']/a/text()
是可以正常的找到我要爬下来的语句的
有没有人帮我看下,感谢
这是一条镜像帖。来源:北邮人论坛 / python / #8819同步于 2015/9/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
搜索引擎 5行小爬虫,为什么老师的是对的 ,我的是错的
BYRTQ
2015/9/27镜像同步19 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
谢谢,确实是这样的
【 在 wanghaohebe 的大作中提到: 】
: 右键 查看源代码 你看看那里面有没有帖子信息就知道了 html.parse获取的就是那个