具有身份验证的urllib.request.urlopen(url) [英] urllib.request.urlopen(url) with Authentication

查看:343
本文介绍了具有身份验证的urllib.request.urlopen(url)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来我一直在玩漂亮的汤和解析网页.我一直在使用一行代码,这是我编写的所有脚本中的救星.代码行是:

I've been playing with beautiful soup and parsing web pages for a few days. I have been using a line of code which has been my saviour in all the scripts that I write. The line of code is :

r = requests.get('some_url', auth=('my_username', 'my_password')).

但是...

我想用(打开具有身份验证的URL)做同样的事情:

I want to do the same thing with (OPEN A URL WITH AUTHENTICATION):

(1) sauce = urllib.request.urlopen(url).read() (1)
(2) soup = bs.BeautifulSoup(sauce,"html.parser") (2)

我无法打开URL并读取需要身份验证的网页. 我如何实现这样的目标:

I'm not able to open a url and read, the webpage which needs authentication. How do I achieve something like this :

  (3) sauce = urllib.request.urlopen(url, auth=(username, password)).read() (3) 
instead of (1)

推荐答案

看看

这篇关于具有身份验证的urllib.request.urlopen(url)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆