Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 remove tags from BeautifulSoup result
#1
Please, I am just learning:
Can anyone tell me how I can remove the tags in the below output(Result) and get my answer in an array like
Address = [a,b,c,d,r......]
from bs4 import BeautifulSoup as bs
print('bs4 imported.')
#
url = 'https://www.planetware.com/tourist-attractions-/oslo-n-osl-oslo.htm'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'html.parser')
#
address=soup.find_all('p', class_="nospc")
# First 2 addresses of the places of attraction
address
# Result:
Output:
<p class="nospc">Address: Nobels gate 32, N-0268 Oslo</p>, <p class="nospc">Address: Akershus Festning, 0015 Oslo</p>, <p class="nospc">Address: Frederiks gate 2, 0164 Oslo</p>, <p class="nospc">Address: Universitetsgata 13, Oslo</p>, <p class="nospc">Address: Tøyengata 53, 0578 Oslo</p>, <p class="nospc">Address: Bellevue, Oslo</p>, <p class="nospc">Address: Frederiks gate 2, 0164 Oslo</p>, <p class="nospc">Address: Bygdøynesveien 39, 0286 Oslo</p>, <p class="nospc">Address: Kongeveien 5, 0787 Oslo</p>, <p class="nospc">Address: Karl Johansgt. 11, 0154 Oslo</p>, <p class="nospc">Address: Rådhuset, 0037 Oslo</p>, <p class="nospc">Address: Bryggegata 9, 0120 Oslo</p>, <p class="nospc">Address: Sars gate 1, 0562 Oslo</p>, <p class="nospc">Address: Kirsten Flagstads Plass 1, 0150 Oslo</p>]
Larz60+ wrote Jun-05-2019, 09:59 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
for a in address:
    print(a.text)
Output:
Address: Nobels gate 32, N-0268 Oslo Address: Akershus Festning, 0015 Oslo Address: Frederiks gate 2, 0164 Oslo Address: Universitetsgata 13, Oslo Address: Tøyengata 53, 0578 Oslo Address: Bellevue, Oslo Address: Frederiks gate 2, 0164 Oslo Address: Bygdøynesveien 39, 0286 Oslo Address: Kongeveien 5, 0787 Oslo Address: Karl Johansgt. 11, 0154 Oslo Address: Rådhuset, 0037 Oslo Address: Bryggegata 9, 0120 Oslo Address: Sars gate 1, 0562 Oslo Address: Kirsten Flagstads Plass 1, 0150 Oslo
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  weird result trying to remove numbers from a list Exsul 6 177 Aug-27-2019, 05:10 AM
Last Post: perfringo
  Preserving anchor tags in BeautifulSoup graham23s 6 310 May-19-2019, 09:16 AM
Last Post: graham23s
  Remove Empty tags in XML using plain python without lxml library saurabhverma2412 3 1,619 Aug-21-2018, 04:53 PM
Last Post: saurabhverma2412

Forum Jump:


Users browsing this thread: 1 Guest(s)