-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.py
executable file
·63 lines (51 loc) · 1.58 KB
/
extract.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
59
60
61
62
63
import json
import sys
import requests
import lxml.html
url = "https://songwhip.com/"
querystring = {"utm_source":"songwhip-home-paste"}
payload = sys.argv[1]
headers = {
'origin': "https://songwhip.com",
'accept-language': "en-US,en;q=0.9",
'cookie': "__cfduid=de68de6f9e9fc6fc795e27a5e8c4a7c9d1559767541",
'pragma': "no-cache",
'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36",
'content-type': "application/json",
'accept': "*/*",
'cache-control': "no-cache,no-cache",
'authority': "songwhip.com",
'referer': "https://songwhip.com/",
'dnt': "1",
'Postman-Token': "37c18515-02d5-4763-90c2-43684ec0aa26"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
links_page = requests.request("GET", response.json()['url'])
doc = lxml.html.fromstring(links_page.content)
things = doc.xpath('//*[@id="main"]/div/div/div[1]/div[2]/div/div/ul/li')
link_dict = {thing.xpath('.//a')[0].text: thing.xpath('.//a')[0].get('href') for thing in things}
data = {"items":
[
{
"uid": "desktop",
"title": source,
"arg": "copy",
"mods": {
"cmd": {
"valid": True,
"arg": "go",
"subtitle": "Visit Link"
}
},
"autocomplete": source,
"icon": {
"type": "fileicon",
"path": "./icons/" + source + '.png'
},
"variables": {
"url": source,
}
} for source, link in link_dict.items()
]
}
sys.stdout.write(json.dumps(data))