【问题标题】:Scraping a webpage with a pop up alert auth in python 3在 python 3 中使用弹出警报身份验证抓取网页
【发布时间】:2021-10-31 12:34:57
【问题描述】:

我一直在尝试使用 python 3 抓取这个web page,其中登录就像一个弹出警报,你可以看到它here,我尝试使用基本身份验证(https://(用户名):( password)@(url)), mechanize 和 ntlm-auth 不成功,或者我做错了,我需要一个方法来做,希望有人能帮我解决这个问题...

使用 ntlm-auth 我没有收到任何错误,但响应就像没有身份验证的页面,这是我的代码的一部分:

from requests_ntlm import HttpNtlmAuth
import requests as rq

username = 'username'
password = 'password'    

url_prod = 'http://www2.deltron.com.pe/modulos/productos/items/producto.php?item_number=NBHP2B125LA'

sess = rq.Session()
sess.auth = HttpNtlmAuth(username, password)
resp = sess.get(url_prod)

print(resp, resp.text)

【问题讨论】:

    标签: python-3.x authentication web-scraping popup alert


    【解决方案1】:

    我在另一个站点上使用相同的识别弹出窗口遇到了同样的问题,并通过请求的基本身份验证解决了它

    from requests.auth import HTTPBasicAuth
    
    requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
    

    https://docs.python-requests.org/en/latest/user/authentication/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      相关资源
      最近更新 更多