How do I get these outputs in 1 single list or dictionary


from bs4 import BeautifulSoup
import requests

with open("htmlviewer.html") as fp:
    soup = BeautifulSoup(fp, "html.parser")
    gp = soup.find_all("a")
for link in gp:
    bs = link.get('href')

I am using this code to extract links from source code and here is my output -|




I want all the links in 1 single list or dictionary

if I do this

bs = {link.get('href')}

I am getting every single link in new dictionary can anyone help, I am new at coding,

Also how do I select links starting with https and ignore /search, I know very stupid questions but I am week into learning python.


First create an empty list outside the for loop, e.g. links = [] and then inside your for loop do links.append(link.get("href"))

Answered By: ImotVoksim
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.