Comment on Finding the best ticket price – Simple web scraping with PythonComments−jknupp12yA shorter, more comprehensible version:import requestsfrom bs4 import BeautifulSoupfrom urlparse import urljoinURL = 'http://philadelphia.craigslist.org/search/sss?sort=date&quer...BASE = 'http://philadelphia.craigslist.org/cpg/'response = requests.get(URL)soup = BeautifulSoup(response.content)for listing in soup.find_all('p',{'class':'row'}): if listing.find('span',{'class':'price'}): price = int(listing.text[2:6]) if 100 < price <=250: print listing.text print urljoin(BASE, listing.a['href']) + '\n'−danielforsythOP12yThanks for posting this, I am still very new to python and your website has taught me a lot. Appreciate the feedback.−stefap212ythanks
Comments
A shorter, more comprehensible version:
import requests
from bs4 import BeautifulSoup
from urlparse import urljoin
URL = 'http://philadelphia.craigslist.org/search/sss?sort=date&quer...
BASE = 'http://philadelphia.craigslist.org/cpg/'
response = requests.get(URL)
soup = BeautifulSoup(response.content)
for listing in soup.find_all('p',{'class':'row'}):
Thanks for posting this, I am still very new to python and your website has taught me a lot. Appreciate the feedback.
thanks