-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from Yolo-cell-hash/dom-branch
DOM Extraction Script add
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# DOM Extraction Script | ||
|
||
Extract the DOM elements of a webpage efficiently. | ||
|
||
## Installation | ||
|
||
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install the required libraries. | ||
|
||
```bash | ||
pip install requests beautifulsoup4 | ||
|
||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
url = 'https://example.com' | ||
``` | ||
Replace 'https://example.com' with the URL of the website you want to extract the DOM from. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
# Define the URL of the website you want to extract the DOM from | ||
url = 'https://example.com' | ||
|
||
response = requests.get(url) | ||
|
||
if response.status_code == 200: | ||
soup = BeautifulSoup(response.text, 'html.parser') | ||
|
||
|
||
title = soup.title | ||
if title: | ||
print("Page Title:", title.text) | ||
else: | ||
print("No title tag found.") | ||
|
||
|
||
links = soup.find_all('a') | ||
print("Links in the page:") | ||
for link in links: | ||
print(link.get('href')) | ||
|
||
else: | ||
print("Failed to retrieve the page. Status code:", response.status_code) |