8
\$\begingroup\$

Usually when performing an internet challenge, there's no problem with having to specify a user agent, but when it comes to dealing with Google, it changes.

Google blacklists the Urllib user agent, presumably to stop spambots, so you have to specify a user agent. This takes up many bytes, and is frankly rather annoying.

Example 1. Example 2. Example 3.

Note: I have updated my Python answers to use the tip suggested below

So how do you get around this problem using the shortest number of bytes?

\$\endgroup\$
  • \$\begingroup\$ Are you sure this question isn't missing a language tag? \$\endgroup\$ – Peter Taylor Aug 7 '15 at 15:07
  • \$\begingroup\$ @PeterTaylor Well although the question is oriented towards Python, I was hoping that the solution could be used to help with other languages \$\endgroup\$ – Beta Decay Aug 7 '15 at 15:12
4
\$\begingroup\$

The requests module, if allowed, is much shorter and easier than urllib in Python (2 and 3):

__import__('requests').get('url').text

On my computer, the user agent defaults to:

python-requests/2.3.0 CPython/3.4.3 Darwin/14.3.0
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.