Skip to content

Commit c2f261a

Browse files
Merge pull request #86 from Sapna2001/webpageLinks
Links for webpage
2 parents 2048111 + eb80708 commit c2f261a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Script to get all links from a webpage
2+
3+
1. Open your browser and go to the required webpage.
4+
2. Launch Developer Tools in your Chrome browser
5+
6+
Go to your Chrome , and under the Developer Tools. For Windows / Mac , you can press F12 function key. Alternatively the short cut keys for Windows is “Control + Alt + I”, for Mac it is “Option + Command + I”. If you prefer to use the mouse instead, point to the hamburger menu (the 3 dots) on the Chrome top right corner. Click on it and the Developer Tools is in here
7+
8+
![Developer Tools](https://user-images.githubusercontent.com/56690856/96709775-ca11b380-13b8-11eb-93a3-c277a3945cc9.png)
9+
10+
3. Open console as shown below.
11+
12+
![Console](https://user-images.githubusercontent.com/56690856/96709786-cc740d80-13b8-11eb-8a8e-1437625f7067.png)
13+
14+
4. Open the script.
15+
5. Now copy the whole code and paste it into the console section.
16+
![Script](https://user-images.githubusercontent.com/56690856/96709790-cd0ca400-13b8-11eb-98c9-10f78bbc1afa.png)
17+
6. Wait for the script to do its job.
18+
19+
![Result](https://user-images.githubusercontent.com/56690856/96709795-cda53a80-13b8-11eb-9801-94875adc4db8.png)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// select all the <a> tags
2+
var selectTag = document.querySelectorAll("a");
3+
// an array to store the title of the link and the link
4+
var array = [];
5+
for (var i = 0; i < selectTag.length; i++) {
6+
var text = selectTag[i].textContent;
7+
var text = text.replace(/\s+/g, " ").trim();
8+
var link = selectTag[i].href;
9+
array.push([text, link]);
10+
}
11+
// Function to create the table with title and link
12+
function make_table() {
13+
// table to store the data
14+
var table = "<table><thead><th>Name</th><th>Links</th></thead><tbody>";
15+
for (var i = 0; i < array.length; i++) {
16+
table +=
17+
"<tr><td>" + array[i][0] + "</td><td>" + array[i][1] + "</td></tr>";
18+
}
19+
var w = window.open("");
20+
// displays the table in a new window
21+
w.document.write(table);
22+
}
23+
make_table();

0 commit comments

Comments
 (0)