使用google进行关键字搜索的域名采集。

来源:互联网 发布:mosh 端口 编辑:程序博客网 时间:2024/05/17 03:09


这里是对 “茶叶“ 关键字进行自动采集,并保存和打印相关域名。

下面例子是搜索google上面的茶叶相关网站的前2页得例子


# -*- coding: utf-8 -*-import pam,timeimport urllib.parse as upfrom bs4 import BeautifulSoupqtxt='茶叶'  #关键字namelist=[]def get():    soup=BeautifulSoup(ie.outerHTML())    for i in soup.findAll('a'):        text=i.get('href')        try:            if text.startswith(r'http://') and 'google' not in text:                namelist.append((text,up.urlparse(text).netloc))        except:            passie=pam.PAMIE()ie.navigate('http://www.google.com/ncr')ie.navigate('https://www.google.com/')ie.setTextBox('q',qtxt)a=ie.findElement('button','name','btnK')ie.clickElement(a)get()for i in range(2,3):#页面数    time.sleep(2)    ie.clickLink(str(i))    #time.sleep(1)    get()namelist=list(set(namelist))for i in namelist:    print (i[1])    print (i[1],file=open(r'dns.txt','at'))ie.quit()


原创粉丝点击