Beautiful Soup Craigslist Scraping Pricing is the same
Emily Wong
I am trying to scrape Craigslist using BeautifulSoup4. All data shows properly EXCEPT price. I can't seem to find the right tagging to loop through pricing instead of showing the same price for each post.
import requests
from bs4 import BeautifulSoup
source = requests.get(').text
soup = BeautifulSoup(source, 'lxml')
for summary in soup.find_all('p', class_='result-info'): pricing = soup.find('span', class_='result-price') price = pricing title = summary.a.text url = summary.a['href'] print(title + '\n' + price.text + '\n' + url + '\n')Snippet of code running through terminal. Pricing is the same for each post.
Thank you
1 Answer
Your script is almost correct. You need to change the soup object for the price to summary
import requests
from bs4 import BeautifulSoup
source = requests.get(').text
soup = BeautifulSoup(source, 'lxml')
for summary in soup.find_all('p', class_='result-info'): price = summary.find('span', class_='result-price') title = summary.a.text url = summary.a['href'] print(title + '\n' + price.text + '\n' + url + '\n')Output:
Boat Water Tender - 10 Tri-Hull with Electric Trolling Motor
$629
1987 Boston Whaler Montauk 17
$25450
1971 Westerly Warwick Sailboat
$3900
Buy or Rent. DC Party Pontoon for Dock Parties or Cruises
$15000
West Marine Zodiac Inflatable Boat SB285 With 5HP Gamefisher (Merc)
$850
2012 AB aluminum/hypalon inflatable dinghy/2012 Yamaha 6hp four stroke
$3400
RHODES-18’ CENTERBOARD DAYSAILER
$6500
Mercury Outboard 7.5 HP
$250
8 hp yamaha 2 stroke
$0
TRADE 38' BENETEAU IDYLLE 1150
$35000
5-hp Top Tank Mercury
$0
5-hp Top Tank Mercury
$0
Wanted ur unwanted outboards
$0
Grumman Sport Boat
$2250
1996 Carver 355 Aft Cabin Motor Yacht
$47000
Lower unit, long shaft
$50
Lower unit, long shaft
$50
Lower unit, long shaft
$50
Lower unit, long shaft
$50
Cape Dory 25 Sailboat for sale or trade
$6500
West Marine HP-V 350
$1200 0