gsearch_test.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import googlesearch
  2. import codecs
  3. import sys
  4. import time
  5. import dataset
  6. import os
  7. import datetime
  8. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  9. table=db['hhh_contentgap_serp']
  10. #print(os.path.realpath('.'))
  11. curdir=os.path.realpath('.')
  12. #fr=codecs.open(curdir+os.sep+'contentgap.txt','r','utf-8')
  13. fr=codecs.open(curdir+os.sep+'hhh\\seo\\contentgap.txt','r','utf-8')
  14. lines=fr.readlines()
  15. lst=[]
  16. for l in lines:
  17. lst.append(l.replace('\n',''))
  18. for l in lst:
  19. #for l in lst[25:]:
  20. #for l in lst[26:]:
  21. time.sleep(5)
  22. ## results=googlesearch.search(l, num_results=150,proxy="https://109.173.102.90:8000/")
  23. results=googlesearch.search(l, num_results=150,proxy="https://217.147.1.166:40998/")
  24. # results=googlesearch.search(l, num_results=150)
  25. idx=0
  26. for r in results:
  27. print(idx)
  28. print(r)
  29. if 'hhh.com.tw' in r:
  30. print('found')
  31. print(idx)
  32. table.insert({'kw':l,'ranking':idx,'dt':datetime.datetime.now()})
  33. db.commit()
  34. break
  35. idx+=1
  36. sys.exit()