-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
58 lines (52 loc) · 1.84 KB
/
scraper.py
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
# This is a template for a Python scraper on morph.io (https://morph.io)
# including some code snippets below that you should find helpful
# import scraperwiki
# import lxml.html
#
# # Read in a page
# html = scraperwiki.scrape("http://foo.com")
#
# # Find something on the page using css selectors
# root = lxml.html.fromstring(html)
# root.cssselect("div[align='left']")
#
# # Write out to the sqlite database using scraperwiki library
# scraperwiki.sqlite.save(unique_keys=['name'], data={"name": "susan", "occupation": "software developer"})
#
# # An arbitrary query against the database
# scraperwiki.sql.select("* from data where 'name'='peter'")
# You don't have to do things with the ScraperWiki and lxml libraries.
# You can use whatever libraries you want: https://morph.io/documentation/python
# All that matters is that your final data is written to an SQLite database
# called "data.sqlite" in the current working directory which has at least a table
# called "data".
import scraperwiki
import lxml.html
import uuid
import datetime
# Blank Python
ASINS = ["B00OS5MTCA","B082VZWBRK","B010TQY7A8","B07RT2XQMY","B013WC0P2A"]
summary = ""
for asin in ASINS:
url = "http://www.amazon.com/dp/"+asin
print(url)
html = scraperwiki.scrape(url)
print(html)
root = lxml.html.fromstring(html)
print(root)
for title in root.cssselect("span[id='btAsinTitle']"):
print(title)
summary += title.text +": "
break
for price in root.cssselect("span[id='actualPriceValue'] b"):
summary += price .text +"<br>"
break
summary += url + "<br>"
now = datetime.datetime.now()
data = {
'link': "http://www.amazon.com/"+"&uuid="+str(uuid.uuid1()),
'title': "Price Monitoring " + str(now),
'description': summary,
'pubDate': str(now) ,
}
scraperwiki.sqlite.save(unique_keys=['link'],data=data)