How would i use python generator to have cleaner code

2018-04-22 23:44:47

I'm trying to figure out a way to run this same exact script with less line of code, as you can see i have multiple functions that are quite identical, but it is necessary for the logic.

What should i do to make it look more cleaner ?

this is what i have so far

spider.py

search_item = input("Input The Search Item: ")

location = input("Location:")

second_location = input("Second Location:")

third_location = input("Third Location:")

# city = [

# "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "Fort Worth",

# "San Diego", "Dallas", "San Jose", "Austin", "Columbus", "Indianapolis", "Seattle", "St. Paul", "Nashville",

# "Louisville", "Plano"

# ]

# rancity = random.choice(city)

class YellowSpider(scrapy.Spider):

name = "yellow"

# start_urls = [

# "https://www.yellowpages.com/search?search_terms=" + search_item + "&geo_location_terms=" + location

# # "https://www.yellowpages.com/search?search_te