Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Fetch all links from a given webpage

import requests as rq
from bs4 import BeautifulSoup

url = input("Enter Link: ")
if ("https" or "http") in url:
    data = rq.get(url)
else:
    data = rq.get("https://" + url)
soup = BeautifulSoup(data.text, "html.parser")
links = []
for link in soup.find_all("a"):
    links.append(link.get("href"))

# Writing the output to a file (myLinks.txt) instead of to stdout
# You can change 'a' to 'w' to overwrite the file each time
with open("myLinks.txt", 'a') as saved:
    print(links[:10], file=saved)
Comment

PREVIOUS NEXT
Code Example
Python :: separete even and odd numbers from a list by filter in python 
Python :: load SQLite db into memory 
Python :: how do i add two matrix and store it in a list in python 
Python :: how to plot graph between f1 score and random forest parameters 
Python :: DOWNLOAD ANALYZE_DXP.PY 
Python :: How to query one to many on same page 
Python :: how to seperate the script from html template when using jQuery in flask 
Python :: How deploy Flask application on Webfaction 
Python :: socialscan 
Python :: extracting code blocks from Markdown 
Python :: Like strings (and all other built-in sequence type), lists can be indexed and sliced: 
Python :: Frog Jump time complexity 
Python :: ring Create Lists 
Python :: ring Using This in the class region as Self 
Python :: candelstick chart matplotlib 
Python :: echo linux with ANSI escape sequence for change output color 
Python :: mehrzeiliges kommentar python 
Python :: how to store file into folder bucket aws 
Python :: python message from byte 
Python :: matplotlib bring plot to front in plots with twin axis 
Python :: I want to add a new column to the DataFrame containing only the month of the measurement 
Python :: gspread how to put shhet number in a variable 
Python :: how to insert value in admin panel in django 
Python :: jupyter notebook save as python script without terminal prompts line numbers 
Python :: While importing we detected an older version of numpy in 
Python :: python http handler iis 
Python :: advanced use of tuples in python 
Python :: branchless if python 
Python :: remove uppercase letters python 
Python :: How split() works when maxsplit is specified 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =