Skip to content

update crawl_google_results.py #1932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web_programming/crawl_google_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

print(len(links))
for link in links:
webbrowser.open(f"http://google.com{link.get('href')}")
while (link.text == "Maps"): webbrowser.open(f"{link.get('href')}")[:0]
Copy link
Member

@cclauss cclauss May 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many things confuse me about this single line of code!

  1. What search term would show us why this change is useful?
  2. Why use while instead of if? Won’t that send us in an infinite loop?
  3. Why put the parentheses around link.text == "Maps"? This is Python, not C.
    • psf/black will remove these.
  4. Why put the conditional and the statement on the same line?
    • psf/black will put them on separate lines.
  5. Why create an f-string that contains no {}?
  6. webbrowser.open() will always return None so why try to slice None?
  7. >>> 'abc'[:0] is the empty string (''). Why try to create an empty slice and then not use it?

Please explain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. Your criticisms are well founded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The search term used was "bitcoin"
  2. You are correct, I misused the while statement.
  3. You are correct.
  4. You are correct.
  5. Each statement has f strings.
  6. To solve the while problem I created for myself, inadvertently.
  7. You are correct.

else: webbrowser.open(f"http://google.com{link.get('href')}")