Python - get redirected URL from Google's “I f

2019-08-21 15:34发布

I need to write a Python function that all it does is to take a link from Google's "I feel lucky" or Duckduckgo's "I'm feeling ducky" and return its redirection. for example, the function shuld take :

http://www.google.com/search?q="stackoverflow"&btnI

or

https://duckduckgo.com/?q=!stackoverflow

and return:

http://stackoverflow.com/

I searched and didn't found a thing. Thanks.

1条回答
我命由我不由天
2楼-- · 2019-08-21 16:20

Well, you can use the requests package:

import requests

var = requests.get(r'http://www.google.com/search?q="stackoverflow"&btnI')
print var.url
查看更多
登录 后发表回答