
from bs4 import BeautifulSoup
import re

fh = open("sites.htm", "r")
soup = BeautifulSoup(fh, "html.parser")

for columnDiv in soup.h1.next_sibling.next_sibling:
	for state in columnDiv:
		for city in state:
			print(city)

#print(soup.text)
print("\n----Done----\n\n")


from bs4 import BeautifulSoup
import re

def getCities():

	fh = open("sites.htm", "r")
	soup = BeautifulSoup(fh, "html.parser")
	placesDict = {}

	for columnDiv in soup.h1.next_sibling.next_sibling:
		for state in columnDiv:
			for city in state:
				m = (re.search('<li><a href="(.+)">(.+)</a>', str(city)))
				if m:			
					placesDict[m.group(2)] = m.group(1)

	return(placesDict)

getCities()

Complete site scraper for all American cities
Complete site scraper for all American cities

areaScraper.py contains the getCities() function, which will
return a dictionary of 'city name string' : 'url string'
for each Craigslist "site", corresponding to American cities,
regions, etc.

  
  from bs4 import BeautifulSoup
  import re
  
+ def getCities():
- fh = open("sites.htm", "r")
- soup = BeautifulSoup(fh, "html.parser")
  
+ 	fh = open("sites.htm", "r")
+ 	soup = BeautifulSoup(fh, "html.parser")
+ 	placesDict = {}
- for columnDiv in soup.h1.next_sibling.next_sibling:
- 	for state in columnDiv:
- 		for city in state:
- 			print(city)
  
- #print(soup.text)
- print("\n----Done----\n\n")
+ 	for columnDiv in soup.h1.next_sibling.next_sibling:
+ 		for state in columnDiv:
+ 			for city in state:
+ 				m = (re.search('<li><a href="(.+)">(.+)</a>', str(city)))
+ 				if m:			
+ 					placesDict[m.group(2)] = m.group(1)
  
+ 	return(placesDict)
+ 
+ getCities()
+ 
Complete site scraper for all American cities
## Code Before:

from bs4 import BeautifulSoup
import re

fh = open("sites.htm", "r")
soup = BeautifulSoup(fh, "html.parser")

for columnDiv in soup.h1.next_sibling.next_sibling:
	for state in columnDiv:
		for city in state:
			print(city)

#print(soup.text)
print("\n----Done----\n\n")

## Instruction:
Complete site scraper for all American cities
## Code After:

from bs4 import BeautifulSoup
import re

def getCities():

	fh = open("sites.htm", "r")
	soup = BeautifulSoup(fh, "html.parser")
	placesDict = {}

	for columnDiv in soup.h1.next_sibling.next_sibling:
		for state in columnDiv:
			for city in state:
				m = (re.search('<li><a href="(.+)">(.+)</a>', str(city)))
				if m:			
					placesDict[m.group(2)] = m.group(1)

	return(placesDict)

getCities()
