Python抓取爱站关键词排名数据

Python批量下载爱站的关键字排名数据,非常好用。直接上代码:

# -*- coding: utf-8 -*-
from cPAMIE import PAMIE
import os
from BeautifulSoup import BeautifulSoup
import time

ie = PAMIE()
fo = open("keys.txt", "a")

i = 1
for i in range(1, 51):
    print i
    ie.navigate("http://baidurank.aizhan.com/baidu/www.jiadingqiang.com/%s/position/" % i)
    time.sleep(7)
    content = ie.pageGetText().encode('utf8') 
    soup = BeautifulSoup(content, fromEncoding="utf8")
    keys = soup.findAll('td', attrs = {'class':'blue t_l word'})
    for k in keys:
        key = k('a')[0].contents[0]
        print key
        fo.write(str(key))
        fo.write('\n')

    i=i+1

fo.close()

 

需要安装PAMIE第三方包才能运行。

写完后发现这个工具挺不错的,http://sunweiwei.com/1171/,推荐一下。сколько стоит проверка на детекторе лжипотолочная люстра в

Leave a Comment