-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjimbo.py
55 lines (34 loc) · 1.27 KB
/
jimbo.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
import requests, bs4
song = input('Enter your song: ')
artist = input('Enter artist: ')
discogs_url = 'https://www.discogs.com/'
url = f'https://www.discogs.com/search/?q={song}+{artist}&type=all'
# Page 1
discogs = requests.get(url)
discogs.raise_for_status()
bSoup = bs4.BeautifulSoup(discogs.text, 'html.parser')
linkElem = bSoup.select('#search_results > div:nth-child(1) > h4 > a')
new_url = linkElem[0].get('href')
discogs_url_1 = discogs_url + new_url
# Page 2
discogs = requests.get(discogs_url_1)
discogs.raise_for_status()
# Genre
bSoup = bs4.BeautifulSoup(discogs.text, 'html.parser')
classElem = bSoup.find_all("div", {"class": "content_3IW3p"})
info_list = []
for i in range(len(classElem)):
# print(classElem[i].getText())
info_list.append(classElem[i].getText())
with open('test.csv', 'a') as csv_file:
csv_file.write(info_list[-2] + '\n')
csv_file.write(info_list[-1] + '\n')
print(info_list[-2])
print(info_list[-1])
# genreElem = bSoup.select('#page_content > div.body > div.profile > div:nth-child(3)')
# for i in range(len(genreElem)):
# print(genreElem[i].getText())
# # Style
# styleElem = bSoup.select('#page_content > div.body > div.profile > div:nth-child(5)')
# for i in range(len(styleElem)):
# print(styleElem[i].getText())