import googlesearch import codecs import sys import time import dataset import os import datetime db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4') table=db['hhh_contentgap_serp'] #print(os.path.realpath('.')) curdir=os.path.realpath('.') #fr=codecs.open(curdir+os.sep+'contentgap.txt','r','utf-8') fr=codecs.open(curdir+os.sep+'hhh\\seo\\contentgap.txt','r','utf-8') lines=fr.readlines() lst=[] for l in lines: lst.append(l.replace('\n','')) for l in lst: #for l in lst[25:]: #for l in lst[26:]: time.sleep(5) ## results=googlesearch.search(l, num_results=150,proxy="https://109.173.102.90:8000/") results=googlesearch.search(l, num_results=150,proxy="https://217.147.1.166:40998/") # results=googlesearch.search(l, num_results=150) idx=0 for r in results: print(idx) print(r) if 'hhh.com.tw' in r: print('found') print(idx) table.insert({'kw':l,'ranking':idx,'dt':datetime.datetime.now()}) db.commit() break idx+=1 sys.exit()