Home > OS >  How to add new data to an array in Python?
How to add new data to an array in Python?

Time:10-16

What is wrong in my code ? I would like to add all urls from website to the array

    import requests
from bs4 import BeautifulSoup

url = 'https://globalthiel.pl'
reqs = requests.get(url)
soup = BeautifulSoup(reqs.text, 'html.parser')

urls = []
for link in soup.find_all('a'):
    url.append(link.get('href').text)
for i in urls:
    print(i, end="")

CodePudding user response:

You have a typo in your code. Replace

url.append(link.get('href').text)

with

urls.append(link.get('href').text)
  • Related