Python Forum
please help me remove error for string.strip()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
please help me remove error for string.strip()
#1
Smile 
#!/usr/bin/python3

from bs4 import BeautifulSoup
import requests
import lxml
import csv


URL = "https://sandiego.craigslist.org/search/sof"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "lxml")

# h3 tag
job_heading = []
for a in soup.find_all("h3"):
    job_heading.append(a.string.strip())

# location
time = []
for b in soup.find_all("time"):
    time.append(b.string.strip())

with open('output.csv', 'w') as file:
    writer = csv.writer(file, delimiter=',')

    writer.writerow(["job_heading", "time"])

    for i in range(25):
        writer.writerow([
            job_heading[i],
            time[i]
        ])
please, help me remove this error so after running this script, there is no "AtributeError: 'NoneType' object has no attribute 'strip'" thanks.
Reply


Messages In This Thread
please help me remove error for string.strip() - by jamie_01 - Oct-14-2022, 06:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove gilberishs from a "string" kucingkembar 2 303 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  extract only text strip byte array Pir8Radio 7 3,053 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Remove a space between a string and variable in print sie 5 1,846 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  How do I remove spurious "." from a string? Zuhan 7 2,108 Apr-12-2022, 02:06 PM
Last Post: Pedroski55
  Can't strip extra characters from Data Canflyguy 7 1,905 Jan-10-2022, 02:16 PM
Last Post: Canflyguy
  strip() pprod 8 3,552 Feb-16-2021, 01:11 PM
Last Post: buran
  How to remove char from string?? ridgerunnersjw 2 2,597 Sep-30-2020, 03:49 PM
Last Post: ridgerunnersjw
  Remove from end of string up to and including some character lbtdne 2 2,371 May-17-2020, 09:24 AM
Last Post: menator01
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,900 May-15-2020, 01:37 PM
Last Post: snippsat
  Need help with code for my WS2812B (Neopixel) Led Strip Phibbl 1 2,800 Apr-08-2020, 07:18 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020