forked from luozhaohui/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueryEBookReaderSales.py
More file actions
executable file
·59 lines (44 loc) · 2.2 KB
/
queryEBookReaderSales.py
File metadata and controls
executable file
·59 lines (44 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# coding=utf-8
# install chromedriver
# https://sites.google.com/a/chromium.org/chromedriver/
#
# unzip chromedriver and add the path to ~/.bashrc
#
from selenium import webdriver
import time
url_dict = {
# 'iReader Plus 黑': 'https://detail.tmall.com/item.htm?spm=a1z10.5-b-s.w4011-14439296382.49.s2cXT1&id=530386199851&sku_properties=5919063:6536025',
# 'iReader 青春版': 'https://detail.tmall.com/item.htm?spm=a230r.1.14.6.JsOheI&id=550673734838',
# 'Kindle 基本款': 'https://detail.tmall.com/item.htm?spm=a1z10.1-b-s.w5003-16522198144.3.35TBaC&id=534274368086&sku_properties=5919063:6536025',
# 'Kindle PaperWhite 3': 'https://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.1.2Jz0PN&id=522680881881',
# 'Kindle Voyage': 'https://detail.tmall.com/item.htm?spm=a1z10.1-b-s.w5003-16522198144.54.35TBaC&id=522686700744',
'当当电子书': 'https://detail.tmall.com/item.htm?spm=a220o.1000855.0.0.5b122063sZ5zhr&pvid=edbfd735-f1ab-4841-a5f9-cdbfeae30790&pos=1&acm=03037.1003.1.1288281&id=562477657745&scm=1007.12959.83083.100200300000000',
'QQ阅读电子书': 'https://detail.tmall.com/item.htm?spm=a1z10.3-b.w4011-16636505510.42.149d0431jHy7rB&id=555910053652&rn=4679eb02347d211f5686ec4d13cc9867&abbucket=4&sku_properties=1627207:28341',
}
class BrowserData:
def __init__(self, browser, url):
self.browser = browser
self.browser.get(url)
def count(self):
count = 0
try:
count = browser.find_element_by_xpath(
".//*[@id='J_DetailMeta']/div[1]/div[1]/div/ul/li[1]/div/span[2]").text.encode('utf-8')
except Exception as err:
print(err)
count = -1
finally:
return count
def output_sales(browser, info, url):
data = BrowserData(browser, url)
print('{0} 当日月销量为: {1}\n'.format(info, data.count()))
def log_date():
print(time.strftime('%Y-%m-%d', time.localtime(time.time())))
if __name__ == '__main__':
log_date()
browser = webdriver.Chrome()
browser.set_window_size(1, 1)
for (info, url) in url_dict.items():
output_sales(browser, info, url)
# exit
browser.quit()