回答編集履歴

1

コードの追加

2016/02/27 07:41

投稿

spectrum
spectrum

スコア44

test CHANGED
@@ -1 +1,67 @@
1
1
  tomohiro_obaraさん、アドバイスありがとうございました
2
+
3
+
4
+
5
+ 以下のようになりました
6
+
7
+
8
+
9
+ ```
10
+
11
+ import urllib2
12
+
13
+ f = urllib2.urlopen('http://www.amazon.co.jp/gp/offer-listing/4785380322/ref=tmm_hrd_used_olp_sr?ie=UTF8&condition=used&qid=&sr=')
14
+
15
+ html = f.read()
16
+
17
+
18
+
19
+ import re
20
+
21
+ targetCol = re.search(r'olpOfferPrice a-text-bold.*',html)
22
+
23
+ matchPrice = re.search(r'\d,\d+',targetCol.group(0))
24
+
25
+ nowPrice = matchPrice.group(0).replace(",","")
26
+
27
+
28
+
29
+
30
+
31
+ import commands
32
+
33
+
34
+
35
+ oldPrice = commands.getoutput('tail -1 /Users/example/scraping/amazon/priceLog.txt')
36
+
37
+
38
+
39
+ echo1 = commands.getoutput('echo "now price gets cheaper. %s yen"' %nowPrice)
40
+
41
+ echo2 = commands.getoutput('echo "the price is not changing. %s yen"' %nowPrice)
42
+
43
+ echo3 = commands.getoutput('echo "now price gets higher. %s yen"' %nowPrice)
44
+
45
+ write = commands.getoutput('echo %s >> /Users/example/scraping/amazon/priceLog.txt'%nowPrice )
46
+
47
+
48
+
49
+ if int(nowPrice) < int(oldPrice):
50
+
51
+ print echo1
52
+
53
+ print write
54
+
55
+ elif int(nowPrice) == int(oldPrice):
56
+
57
+ print echo2
58
+
59
+ else:
60
+
61
+ print echo3
62
+
63
+ print write
64
+
65
+
66
+
67
+ ```