赞
踩
1.[代码][Python]代码
#-*- coding: UTF-8 -*-
#Python UTF-8 抓取百度关键词V1.0
#key.txt是抓取文件配置
#author PHPer.yang@gmail.com
import cgi,urllib #URL读取
import re #正则匹配
import MySQLdb #MySQL
import datetime #时间
#import time,thread #多线程
"""
MySQL表结构
CREATE TABLE `baidu` (
`id` int(10) unsigned NOT NULL auto_increment,
`url` varchar(200) NOT NULL,
`title` varchar(600) NOT NULL,
`keys` varchar(100) NOT NULL,
`bdurl` varchar(200) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
"""
def Yang_Config ():
fp = open('key.txt','r')
for line in fp.read().split('@'):
word = line.split(',') #word 是字典
#for item in word :
#print item.encode("UTF-8")
#print '------'
if len(word) > 1:
yang_u = word[0]
yang_k = word[1]
Yang_Spider(yang_u,yang_k)
#抓取页面开始
def Yang_Spider(yang_u,yang_k):
url = 'http://www.baidu.com/s?wd=%s+site:%s&&rn=100'% (yang_k,yang_u)
print url
fp = urllib.urlopen(url).read()
#print fp re.search
m = re.findall(r"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。