forked from abhijeetchauhan/GenreClassification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebScrapping.py
More file actions
31 lines (25 loc) · 789 Bytes
/
webScrapping.py
File metadata and controls
31 lines (25 loc) · 789 Bytes
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
from bs4 import BeautifulSoup as bs
import urllib
import re
import sys
import numpy
import json
# List of urls present which contain link to books specific to one genre
urls = [
"https://www.gutenberg.org/wiki/Technology_(Bookshelf)"
]
# To store book name and number pair for specific genre
bookNoList = {}
for url in urls:
html = urllib.urlopen(url).read()
soup = bs(html, "lxml")
# To find the a tags with href and iterate over that list
for a in soup.find_all('a', href=True):
bookNo = re.findall(r'[0-9]+',a['href'])
if len(bookNo) == 1:
bookNo = str(bookNo)
#print bookNo
bookNoList[a.text] = bookNo[2:len(bookNo) - 2]
# a.text for name of the book
with open('Technology.txt', 'w') as outfile:
json.dump(bookNoList, outfile)