123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- from typing import NoReturn
- from selenium import webdriver
- import time
- import networkx as nx
- import dataset
- import pickle
- import codecs
- from selenium.webdriver.common import keys
- from selenium.webdriver.common.keys import Keys
- import sys
- import os
- import time
- import re
- import pandas as pd
- import df2sheet
- from browser_common import JBrowser
- import datetime
- import dataset
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
- def find_master_by_designer(masters,designer):
- for m in masters:
- if m['designer']==designer:
- return m
- def get_designer_statistics(designer_list):
- global db
- jb=JBrowser()
- jb.set_profile_path("Profile 7")
-
-
-
-
-
-
-
-
- details=[]
- masters=[]
- table=db['customer_list']
- table_details=db['rank_details']
- table_summary=db['rank_summary']
- for tup in designer_list:
- q=tup[0]
- vip=tup[1]
- googleurl='https://www.google.com/search?q='+q
- jb.get(googleurl)
- driver=jb.get_driver()
- time.sleep(3)
- elmts=driver.find_elements_by_xpath("//div[@class='TbwUpd NJjxre']/cite")
- idx=1
- ranking=-1
- searchhome=-1
- hhh=-1
- com100=-1
- txt=None
- href=None
- for elmt in elmts:
- elmt_titl3=elmt.find_element_by_xpath("../..//h3")
- elmt_href=elmt.find_element_by_xpath("../..")
- print(elmt_titl3.text)
- print(elmt_href.text)
- txt=elmt_titl3.text
- href=elmt_href.text
- print(idx)
- print(len(elmts))
- print(txt)
- print(href)
- if not ('google.com' in href):
- if '100.com' in href:
- com100=idx
- if 'searchome' in href:
- searchhome=idx
- if 'hhh.com.tw' in href:
- hhh=idx
- ranking=idx
- print("updsert")
- print({'name':q,'updated':datetime.datetime.now()})
- table.upsert({'name':q,'updated':datetime.datetime.now()},keys=['name'])
- m={'designer':q,'title':txt,'url':href,'hhh':hhh,'dt':datetime.datetime.now(),'searchome':searchhome,'c_100':com100,'vip':vip}
- masters.append(m)
- table_summary.insert(m)
- print(href)
- print(txt)
-
- dtstr=datetime.datetime.now().strftime("%Y-%m/%d %H:%M:%S")
- d={'designer':q,'title':txt,'url':href,'ranking':idx}
- details.append(d)
- table_details.insert({'q':q,'dt':datetime.datetime.now(),'designer':d['designer'],'title':d['title'],'url':d['url'],'ranking':idx,'hhh':hhh,'searchome':searchhome,'c_100':com100})
- idx+=1
- if ranking==-1:
- ranking=idx
- print("updsert")
- print({'name':q,'updated':datetime.datetime.now()})
- table.upsert({'name':q,'updated':datetime.datetime.now()},keys=['name'])
- m={'designer':q,'title':txt,'url':href,'hhh':hhh,'dt':datetime.datetime.now(),'searchome':searchhome,'c_100':com100}
- masters.append(m)
- table_summary.insert(m)
- db.commit()
- time.sleep(3)
- return {'masters':masters,'details':details}
- qlist=[]
- cursor=db.query('select name,vip from customer_list order by updated asc limit 170')
- for c in cursor:
- qlist.append((c['name'],c['vip']))
- get_designer_statistics(qlist)
|