import scrapy
from locations.items import GeojsonPointItem
import json
import re

class LaSalsaSpider(scrapy.Spider):
    name = "la_salsa"
    allowed_domains = ["www.lasalsa.com"]
    start_urls = (
        'http://lasalsa.com/wp-content/themes/lasalsa-main/locations-search.php?lat=0&lng=0&radius=99999999',
    )

    def parse(self, response):
        restaurantData = response.xpath("//markers").extract_first()
        matches = re.finditer("<marker [\S\s]+?\"\/>", restaurantData)




        for match in matches:
            matchString = match.group(0)
            fullAddress=re.findall("address=\"(.*?)\"", matchString)[0].replace('&lt;br /&gt;', ',')
            #Accounts for cases with second address line

            yield GeojsonPointItem(
              ref=re.findall("name=\"(.*?)\"", matchString)[0].strip(),
              lat=re.findall("latitude=\"(.*?)\"", matchString)[0].strip(),
              lon=re.findall("longitude=\"(.*?)\"", matchString)[0].strip(),
              addr_full=re.findall("address=\"(.*?)\"", matchString)[0].replace('&lt;br /&gt;', ',').strip(),
              city=re.findall("city=\"(.*?)\"", matchString)[0].strip(),
              state=re.findall("state=\"(.*?)\"", matchString)[0].strip(),
              postcode=re.findall("zip=\"(.*?)\"", matchString)[0].strip(),
              phone=re.findall("phone=\"(.*?)\"", matchString)[0].replace(' ','').strip(),
            )
            
import scrapy

from locations.items import GeojsonPointItem


class LaSalsaSpider(scrapy.Spider):
    name = "la_salsa"
    allowed_domains = ["www.lasalsa.com"]
    start_urls = (
        'http://lasalsa.com/wp-content/themes/lasalsa-main/locations-search.php?lat=0&lng=0&radius=99999999',
    )

    def parse(self, response):
        for match in response.xpath("//markers/marker"):
            yield GeojsonPointItem(
                ref=match.xpath('.//@name').extract_first(),
                lat=float(match.xpath('.//@latitude').extract_first()),
                lon=float(match.xpath('.//@longitude').extract_first()),
                addr_full=match.xpath('.//@address').extract_first(),
                city=match.xpath('.//@city').extract_first(),
                state=match.xpath('.//@state').extract_first(),
                postcode=match.xpath('.//@zip').extract_first(),
                phone=match.xpath('.//@phone').extract_first(),
            )

Use xpath instead of regex
Use xpath instead of regex

  import scrapy
+ 
  from locations.items import GeojsonPointItem
+ 
- import json
- import re
  
  class LaSalsaSpider(scrapy.Spider):
      name = "la_salsa"
      allowed_domains = ["www.lasalsa.com"]
      start_urls = (
          'http://lasalsa.com/wp-content/themes/lasalsa-main/locations-search.php?lat=0&lng=0&radius=99999999',
      )
  
      def parse(self, response):
-         restaurantData = response.xpath("//markers").extract_first()
-         matches = re.finditer("<marker [\S\s]+?\"\/>", restaurantData)
+         for match in response.xpath("//markers/marker"):
+             yield GeojsonPointItem(
+                 ref=match.xpath('.//@name').extract_first(),
+                 lat=float(match.xpath('.//@latitude').extract_first()),
+                 lon=float(match.xpath('.//@longitude').extract_first()),
+                 addr_full=match.xpath('.//@address').extract_first(),
+                 city=match.xpath('.//@city').extract_first(),
+                 state=match.xpath('.//@state').extract_first(),
+                 postcode=match.xpath('.//@zip').extract_first(),
+                 phone=match.xpath('.//@phone').extract_first(),
+             )
  
- 
- 
- 
-         for match in matches:
-             matchString = match.group(0)
-             fullAddress=re.findall("address=\"(.*?)\"", matchString)[0].replace('&lt;br /&gt;', ',')
-             #Accounts for cases with second address line
- 
-             yield GeojsonPointItem(
-               ref=re.findall("name=\"(.*?)\"", matchString)[0].strip(),
-               lat=re.findall("latitude=\"(.*?)\"", matchString)[0].strip(),
-               lon=re.findall("longitude=\"(.*?)\"", matchString)[0].strip(),
-               addr_full=re.findall("address=\"(.*?)\"", matchString)[0].replace('&lt;br /&gt;', ',').strip(),
-               city=re.findall("city=\"(.*?)\"", matchString)[0].strip(),
-               state=re.findall("state=\"(.*?)\"", matchString)[0].strip(),
-               postcode=re.findall("zip=\"(.*?)\"", matchString)[0].strip(),
-               phone=re.findall("phone=\"(.*?)\"", matchString)[0].replace(' ','').strip(),
-             )
-             
Use xpath instead of regex
## Code Before:
import scrapy
from locations.items import GeojsonPointItem
import json
import re

class LaSalsaSpider(scrapy.Spider):
    name = "la_salsa"
    allowed_domains = ["www.lasalsa.com"]
    start_urls = (
        'http://lasalsa.com/wp-content/themes/lasalsa-main/locations-search.php?lat=0&lng=0&radius=99999999',
    )

    def parse(self, response):
        restaurantData = response.xpath("//markers").extract_first()
        matches = re.finditer("<marker [\S\s]+?\"\/>", restaurantData)




        for match in matches:
            matchString = match.group(0)
            fullAddress=re.findall("address=\"(.*?)\"", matchString)[0].replace('&lt;br /&gt;', ',')
            #Accounts for cases with second address line

            yield GeojsonPointItem(
              ref=re.findall("name=\"(.*?)\"", matchString)[0].strip(),
              lat=re.findall("latitude=\"(.*?)\"", matchString)[0].strip(),
              lon=re.findall("longitude=\"(.*?)\"", matchString)[0].strip(),
              addr_full=re.findall("address=\"(.*?)\"", matchString)[0].replace('&lt;br /&gt;', ',').strip(),
              city=re.findall("city=\"(.*?)\"", matchString)[0].strip(),
              state=re.findall("state=\"(.*?)\"", matchString)[0].strip(),
              postcode=re.findall("zip=\"(.*?)\"", matchString)[0].strip(),
              phone=re.findall("phone=\"(.*?)\"", matchString)[0].replace(' ','').strip(),
            )
            
## Instruction:
Use xpath instead of regex
## Code After:
import scrapy

from locations.items import GeojsonPointItem


class LaSalsaSpider(scrapy.Spider):
    name = "la_salsa"
    allowed_domains = ["www.lasalsa.com"]
    start_urls = (
        'http://lasalsa.com/wp-content/themes/lasalsa-main/locations-search.php?lat=0&lng=0&radius=99999999',
    )

    def parse(self, response):
        for match in response.xpath("//markers/marker"):
            yield GeojsonPointItem(
                ref=match.xpath('.//@name').extract_first(),
                lat=float(match.xpath('.//@latitude').extract_first()),
                lon=float(match.xpath('.//@longitude').extract_first()),
                addr_full=match.xpath('.//@address').extract_first(),
                city=match.xpath('.//@city').extract_first(),
                state=match.xpath('.//@state').extract_first(),
                postcode=match.xpath('.//@zip').extract_first(),
                phone=match.xpath('.//@phone').extract_first(),
            )
