ecologits-calculator / src /scrapper.py
vdwow's picture
feat: update to ecologits 0.5.1 + remove own usage to fix it
7f50b6e
raw
history blame contribute delete
796 Bytes
import requests
from bs4 import BeautifulSoup
import tiktoken
tokenizer = tiktoken.get_encoding('cl100k_base')
def process_input(text):
r = requests.get(text, verify=False)
soup = BeautifulSoup(r.text, "html.parser")
print(soup)
list_text = str(soup).split('parts":["')
#print(list_text)
s = ''
for item in list_text[1:int(len(list_text)/2)]:
if list_text.index(item)%2 == 1:
s = s + item.split('"]')[0]
amout_token = tiktoken_len(s)
return amout_token
def tiktoken_len(text):
tokens = tokenizer.encode(
text,
disallowed_special=()
)
return len(tokens)
answer = process_input('https://chatgpt.com/share/6737b9b5-56fc-8002-a212-35339f5b1d5a')
print(answer)