質問編集履歴
2
コードについて
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,129 +36,7 @@
|
|
36
36
|
|
37
37
|
#trial.py
|
38
38
|
|
39
|
-
#!/usr/bin/env python
|
40
39
|
|
41
|
-
# -*- coding: utf-8 -*-
|
42
|
-
|
43
|
-
from selenium import webdriver
|
44
|
-
|
45
|
-
from selenium.common.exceptions import NoSuchElementException
|
46
|
-
|
47
|
-
from selenium.webdriver.common.keys import Keys
|
48
|
-
|
49
|
-
from sys import exit
|
50
|
-
|
51
|
-
from time import sleep
|
52
|
-
|
53
|
-
import argparse
|
54
|
-
|
55
|
-
import datetime
|
56
|
-
|
57
|
-
import requests
|
58
|
-
|
59
|
-
import os
|
60
|
-
|
61
|
-
import urllib2
|
62
|
-
|
63
|
-
import codecs, sys
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
|
68
|
-
|
69
|
-
sys.stdin = codecs.getreader('utf_8')(sys.stdin)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
DELAY_SLEEP = 1
|
74
|
-
|
75
|
-
JANJAN_URL = "https://antlion.xsrv.jp/"
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def main():
|
80
|
-
|
81
|
-
parser = argparse.ArgumentParser(description='Get asin from JANJAN_URL')
|
82
|
-
|
83
|
-
parser.add_argument('--jan', nargs='+')
|
84
|
-
|
85
|
-
args = parser.parse_args()
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
print a
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
products = {}
|
94
|
-
|
95
|
-
for k,v in products.iteritems():
|
96
|
-
|
97
|
-
driver = webdriver.PhantomJS()
|
98
|
-
|
99
|
-
try:
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
driver.implicitly_wait(DELAY_SLEEP)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
# JAN code
|
108
|
-
|
109
|
-
driver.get(JANJAN_URL)
|
110
|
-
|
111
|
-
driver.implicitly_wait(DELAY_SLEEP)
|
112
|
-
|
113
|
-
elem = driver.find_element_by_xpath('//*[@id="content"]/div[1]/div/form/input[2]')
|
114
|
-
|
115
|
-
elem.send_keys(a)
|
116
|
-
|
117
|
-
elem = driver.find_element_by_xpath('//*[@id="content"]/div[1]/div/form/input[3]')
|
118
|
-
|
119
|
-
elem.click()
|
120
|
-
|
121
|
-
elems = driver.find_elements_by_xpath('//*[@id="content"]/div[2]/div[5]/ul/li')
|
122
|
-
|
123
|
-
for e in elems:
|
124
|
-
|
125
|
-
desc = e.get_attribute('textContent')
|
126
|
-
|
127
|
-
if desc.startswith("ASIN"):
|
128
|
-
|
129
|
-
v['asin'] = desc
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
except NoSuchElementException:
|
134
|
-
|
135
|
-
print "not available"
|
136
|
-
|
137
|
-
except Exception as e:
|
138
|
-
|
139
|
-
print e
|
140
|
-
|
141
|
-
driver.close()
|
142
|
-
|
143
|
-
exit(1)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
driver.close()
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
for v in products.values():
|
152
|
-
|
153
|
-
print v['asin']
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
if __name__ == "__main__":
|
160
|
-
|
161
|
-
main()
|
162
40
|
|
163
41
|
```
|
164
42
|
|
1
タグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|