File tree Expand file tree Collapse file tree 1 file changed +26
-22
lines changed Expand file tree Collapse file tree 1 file changed +26
-22
lines changed Original file line number Diff line number Diff line change 3
3
4
4
base_url = "https://www.yelp.com/search?find_desc=Restaurants&find_loc={}&start={}"
5
5
city = "los angeles"
6
+ file_path = 'los_angeles_restaurants.txt'
6
7
8
+ def extract_names (city , file_path ):
9
+ with open (file_path , 'a' ) as file :
10
+ start = 0
11
+ for i in range (100 ):
12
+ url = base_url .format (city , start )
13
+ response = requests .get (url )
14
+ start += 30
15
+ print (f"STATUS CODE: { response .status_code } FOR { response .url } " )
16
+ soup = BeautifulSoup (response .text , 'html.parser' )
17
+ names = soup .findAll ('a' , {'class' : 'biz-name' })
7
18
8
- with open ('los_angeles_restaurants.txt' , 'a' ) as file :
9
- start = 0
10
- for i in range (100 ):
11
- url = base_url .format (city , start )
12
- response = requests .get (url )
13
- start += 30
14
- print (f"STATUS CODE: { response .status_code } FOR { response .url } " )
15
- soup = BeautifulSoup (response .text , 'html.parser' )
16
- names = soup .findAll ('a' , {'class' : 'biz-name' })
19
+ count = 0
20
+ for info in names :
21
+ try :
22
+ title = info .text
23
+ print (title )
24
+ file .write (title + '\n ' )
25
+ count += 1
26
+ except Exception as e :
27
+ print (e )
28
+ print (f"{ count } RESTAURANTS EXTRACTED..." )
29
+ print (start )
30
+ if start == 990 :
31
+ break
17
32
18
- count = 0
19
- for info in names :
20
- try :
21
- title = info .text
22
- print (title )
23
- file .write (title + '\n ' )
24
- count += 1
25
- except Exception as e :
26
- print (e )
27
- print (f"{ count } RESTAURANTS EXTRACTED..." )
28
- print (start )
29
- if start == 30 :
30
- break
33
+
34
+ extract_names (city , file_path )
You can’t perform that action at this time.
0 commit comments