Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d2d7f2

Browse files
wrap code in try except
1 parent 57d47c5 commit 3d2d7f2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎restaurant_names.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
city = "los angeles"
66

77

8-
with open('los_angeles_restaurants.txt', 'w') as file:
8+
with open('los_angeles_restaurants.txt', 'a') as file:
99
start = 0
1010
for i in range(100):
1111
url = base_url.format(city, start)
@@ -19,9 +19,12 @@
1919

2020
count = 0
2121
for info in names:
22-
title = info.text.encode("utf-8")
23-
print(title)
24-
count += 1
25-
file.write(title + '\n')
26-
print(f"{count} RESTAURANTS FOUND...")
22+
try:
23+
title = info.text
24+
print(title)
25+
file.write(title + '\n')
26+
count += 1
27+
except Exception as e:
28+
print(e)
29+
print(f"{count} RESTAURANTS EXTRACTED...")
2730
print(start)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /