-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisbn.py
executable file
·46 lines (36 loc) · 1.13 KB
/
isbn.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
# -*- coding: utf-8 -*-
__author__ = 'Poc'
import re,json,sys,requests,codecs
from BeautifulSoup import BeautifulSoup
reload(sys)
sys.setdefaultencoding('utf8')
_isbn_lst='4710947917212'
_URL_PREFIX='http://search.books.com.tw/exep/prod_search.php?cat=all&key='
def parse_html(data):
soup =BeautifulSoup(data)
soup_price =soup.find('span', {'class' :'price'})
# print(dir(soup_price))
print((soup_price.find('strong').findAll('b')))
print(soup_price.findChildren('<b>'))
print(soup.find('HEAD'))
pass
def fetch_data(isbn):
html_file = 'save_isbn.html'
req_url=_URL_PREFIX+_isbn_lst
# results = requests.get(req_url,
# headers={'User-Agent': 'Mozilla/5.0'})
#
# print(results.text.encode('iso-8859-1'))
# print(results.text.encode('utf-8'))
# parse_html(results.text.encode('iso-8859-1'))
# f = codecs.open(html_file,'w', 'utf-8')
# f.write(results.text.encode('iso-8859-1'))
# f.close()
parse_html( open(html_file,'r').read() )
pass
def main():
print("isbn test")
fetch_data(_isbn_lst)
pass
if __name__ == '__main__':
main()