<jupyter_start><jupyter_text><jupyter_code>!pip install requests
!pip install html5lib
!pip install bs4
#libraries for webscrapping 
import bs4 as bs
import re
import urllib.request as url

#libary to save the data as a csv file
import csv 
locals = []

#Here is a List of Laundry & Dry Cleaners in a target zipcode 
listOfSources = ["https://www.yelp.com/search?find_desc=Laundry%20Services&find_loc=10012",
                 "https://www.yelp.com/search?find_desc=Laundry%20Services&find_loc=10013",
                 "https://www.yelp.com/search?find_desc=Laundry%20Services&find_loc=10014",
                 "https://www.yelp.com/search?find_desc=Laundry%20Services&find_loc=10015",
                 "https://www.yelp.com/search?find_desc=Laundry%20Services&find_loc=10016"
                 ]
for Sour in range(len(listOfSources)):  
  print(listOfSources[Sour])
  source = url.urlopen(listOfSources[Sour])
  page_soup = bs.BeautifulSoup(source, 'html.parser')
  mains = page_soup.find_all("div", {"class": "lemon--div__09f24__1mboc mainAttributes__09f24__26-vh arrange-unit__09f24__1gZC1 arrange-unit-fill__09f24__O6JFU border-color--default__09f24__R1nRO"})
  print(mains)
  #SCRAPPING 
  for main in mains:
      try:
          local = {}
          busname = main.find("a").text
          print("Rest_Name:" + busname)
          ratings = main.find("span", {"class": "lemon--span__09f24__3997G display--inline__09f24__3iACj border-color--default__09f24__R1nRO"}).div.get('aria-label')
          print("Rest_Ratings:" + ratings)
          clas = "lemon--a__09f24__IEZFH link__09f24__1kwXV link-color--inherit__09f24__3PYlA link-size--inherit__09f24__2Uj95"
          #lemon--li__09f24__1r9wz border-color--default__09f24__R1nRO
          address = main.find("a", {"class": clas})
          print("adrress:" + str(address))
          #
          #Return a list containing every occurrence of "ai":
          txt = str(address)
          #SAVING THE NAME 
          local['name'] = busname

          
          if re.search("\/biz\/[A-Za-z0-9-?=]+", txt):
              x = re.findall("\/biz\/[A-Za-z0-9-?=]+",txt)
              link = x[0]
              link = link.replace("/biz","www.yelp.com/biz/")
              link = "https://"+link

              print("_____---- "+ link) 
          elif (re.search("www.[A-Za-z0-9]+.com[A-Za-z0-9%-]+", txt)):
            x = re.findall("www.[A-Za-z0-9]+.com[A-Za-z0-9%-]+", txt)
            link = x[0]
            link = link.replace("%2F","")
            link = link.replace("%2","")
            link = link.replace("combiz","com/biz")
            link = "https://"+link
            print("*********" + link)
          if (len(link) > 0):
            #SAVING THE LINK OF YELP
            local['link'] = link
            print(link)
            print("There is a link ")
            sourceWebSite = url.urlopen(link)
            page_soupDetails = bs.BeautifulSoup(sourceWebSite, 'html.parser')
            theSoup = page_soupDetails.find_all("div", {"class": "lemon--div__373c0__1mboc stickySidebar__373c0__3PY1o border-color--default__373c0__3-ifU"})
            mainInternal = theSoup[0]
            #print(mainInternal)
            #print("*** "  + mainInternal )
            #\([0-9]{3}\) [0-9]{3}-[0-9]{4}


            phoneContent = mainInternal
            if (re.search("\([0-9]{3}\) [0-9]{3}-[0-9]{4}", str(phoneContent))):
                x = re.findall("\([0-9]{3}\) [0-9]{3}-[0-9]{4}",str(phoneContent))
                phoneNumber = x[0]
                print("PHONE NUMBER "+ phoneNumber)
                #SAVING THE PHONE NUMBER
                local['phoneNumber'] = phoneNumber
            else: 
              local['phoneNumber'] = "N/A"
              print("No number available")

            

            #lemon--p__373c0__3Qnnj text__373c0__2U54h text-color--normal__373c0__NMBwo text-align--left__373c0__1Uy60
            #lemon--div__373c0__1mboc arrange-unit__373c0__o3tjT arrange-unit-fill__373c0__3Sfw1 border-color--default__373c0__3-ifU



            #Webiste Address 
            WebsiteClass = "lemon--p__373c0__3Qnnj text__373c0__2U54h text-color--normal__373c0__NMBwo text-align--left__373c0__1Uy60"
            #lemon--li__09f24__1r9wz border-color--default__09f24__R1nRO
            Website = mainInternal.find("p", {"class": WebsiteClass})
            #print("number:" + str(Website))
            txt = str(Website)
            print("WEB ADRESSS " + txt)
            print(txt)
            if (re.search("[A-Za-z0-9]+.com&", txt)):
                x = re.findall("[A-Za-z0-9]+.com&",txt)
                webLink = x[0]
                webLink = webLink.replace("&","")
                webLink = webLink.replace("^2F","https://www.")
                #SAVING THE WEBSITE 
                local['website'] = webLink
                print("WEBLINK: " + webLink)
              
              
                
            else:
              print("No webaddress available")
              local['website'] = "N/A"




          locals.append(local)

      except:
          print(None)
#Run this code to save extracted files as a CSV output
import csv
print(locals)
filename = 'laundryData.csv'
with open(filename, 'w', newline='') as f: 
	w = csv.DictWriter(f,['name','phoneNumber','website', 'link']) 
	w.writeheader() 
	for local in locals: 
		w.writerow(local) 
for local in locals:
  print(local)<jupyter_output>[]
{'fraction_non_alphanumeric': 0.14748334566987417, 'fraction_numerical': 0.04829755736491488, 'mean_word_length': 2.1887905604719764, 'pattern_counts': {'":': 6, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 9, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '29186', 'license': 'MIT', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1833, 'n_words': 300, 'path': 'Bubbles.ipynb', 'repo_name': 'kwadade/Anypic', 'size': '5404'}