作者seiryou (青龙)
看板Python
标题[问题] 有办法写出自动搜寻比对网页关键字吗?
时间Sun Nov 16 16:32:12 2014
例如我每天有想载的东西
我可以事先设定好所有需要的关键字 比如a b c
然後让程式去搜寻比对网页内容
有符合的话就自动去点击相关的连结
接着去点选下载软体同意
请问有可能办到吗?
会很难吗?
感谢回答~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.32.29.11
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1416126734.A.08F.html
1F:推 IAMPF: 找爬虫相关资料 11/16 16:46
感谢 我看了一下
import urllib2
from sgmllib import SGMLParser
class ListName(SGMLParser):
def __init__(self):
SGMLParser.__init__(self)
self.is_h4 = ""
使用一个变量 is_h4 做标记判定 html 文件中的 h4 标签,如果遇到 h4 标签,则将标
签内的内容加入到 List 变量 name 中。
请问这句话是甚麽意思? 听起来像是有个list?加入到list里面是指搜寻网页关键字
然後放进自己list分类吗?
self.name = []
def start_h4(self, attrs):
self.is_h4 = 1
def end_h4(self):
self.is_h4 = ""
def handle_data(self, text):
if self.is_h4 == 1:
self.name.append(text)
到这里为止都是在抓网页关键字然後进行归类吗?
content = urllib2.urlopen('
http://list.taobao.com/browse/cat-0.htm').read()
listname = ListName()
listname.feed(content)
for item in listname.name:
print item.decode('gbk').encode('utf8')
※ 编辑: seiryou (114.32.29.11), 11/16/2014 17:13:01