From the uDemy course on LLM engineering.
https://www.udemy.com/course/llm-engineering-master-ai-and-large-language-models
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.9 KiB
109 lines
2.9 KiB
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "52b6cbd9-5248-4083-94c5-e4d657e44da1", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"#import os\n", |
|
"import requests\n", |
|
"#from dotenv import load_dotenv\n", |
|
"from bs4 import BeautifulSoup\n", |
|
"from IPython.display import Markdown, display\n", |
|
"#from openai import OpenAI\n", |
|
"from selenium import webdriver\n", |
|
"from selenium.webdriver.chrome.service import Service\n", |
|
"from selenium.webdriver.common.by import By\n", |
|
"from selenium.webdriver.chrome.options import Options\n", |
|
"\n", |
|
"class Website:\n", |
|
" url: str\n", |
|
" title: str\n", |
|
" text: str\n", |
|
"\n", |
|
" def __init__(self, url):\n", |
|
" self.url = url\n", |
|
"\n", |
|
" options = Options()\n", |
|
"\n", |
|
" options.add_argument(\"--no-sandbox\")\n", |
|
" options.add_argument(\"--disable-dev-shm-usage\")\n", |
|
"\n", |
|
" service = Service(PATH_TO_CHROME_DRIVER)\n", |
|
" driver = webdriver.Chrome(service=service, options=options)\n", |
|
" driver.get(url)\n", |
|
"\n", |
|
" input(\"Please complete the verification in the browser and press Enter to continue...\")\n", |
|
" page_source = driver.page_source\n", |
|
" driver.quit()\n", |
|
"\n", |
|
" soup = BeautifulSoup(page_source, 'html.parser')\n", |
|
" self.title = soup.title.string if soup.title else \"No title found\"\n", |
|
" for irrelevant in soup([\"script\", \"style\", \"img\", \"input\"]):\n", |
|
" irrelevant.decompose()\n", |
|
" self.text = soup.get_text(separator=\"\\n\", strip=True)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "23818353-a2fc-4c2f-be1e-0677399fa1b5", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"website = Website(\"https://edwarddonner.com\")" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "4452b88b-58aa-4f50-ad39-c5a1c2363025", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"website = Website(\"https://openai.com\")" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "0250145b-2afb-48d6-b43f-daf64329e7af", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"print(website.text)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "97699263-4a06-4e06-905b-9db4a554b75c", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [] |
|
} |
|
], |
|
"metadata": { |
|
"kernelspec": { |
|
"display_name": "Python 3 (ipykernel)", |
|
"language": "python", |
|
"name": "python3" |
|
}, |
|
"language_info": { |
|
"codemirror_mode": { |
|
"name": "ipython", |
|
"version": 3 |
|
}, |
|
"file_extension": ".py", |
|
"mimetype": "text/x-python", |
|
"name": "python", |
|
"nbconvert_exporter": "python", |
|
"pygments_lexer": "ipython3", |
|
"version": "3.11.11" |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 5 |
|
}
|
|
|