-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.py
More file actions
39 lines (31 loc) · 1.11 KB
/
func.py
File metadata and controls
39 lines (31 loc) · 1.11 KB
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
from bs4 import BeautifulSoup
import requests
import json
def get_first_receipts(from_url):
request = requests.get(url=from_url)
soup = BeautifulSoup(request.text, "html.parser")
receipts = soup.find_all("h3", class_="horizontal-tile__item-title item-title")
receipts_arr = []
for receipt in receipts:
receipt_url = f'https://eda.ru{receipt.find("a")["href"]}'
receipts_arr.append(receipt_url)
# return receipts_dict
# print(receipts_dict)
with open("receipts_dict.json", "w") as file:
json.dump(receipts_arr, file, indent=4)
def write_to_json(name, url):
with open("user_books.json", 'r') as jfr:
jf_file = json.load(jfr)
with open("user_books.json", 'w') as jf:
if name not in jf_file.keys():
jf_file[name] = []
json.dump(jf_file, jf, indent=4)
return
if url in jf_file[name]:
json.dump(jf_file, jf, indent=4)
return
if not url:
json.dump(jf_file, jf, indent=4)
return
jf_file[name].append(str(url))
json.dump(jf_file, jf, indent=4)