使用auth在python中保持活动

时间:2018-08-26 20:50:02

标签: python request

我想通过身份验证来请求GET请求,而不是从其他某个URL检索内容,从而使连接保持活力。我知道如何在R中做到这一点:

sess <- html_session("http://www.sudacka-mreza.hr/sudska-praksa.aspx", encoding = "UTF-8")
form <- html_form(sess)[[1]]
fill_form <- set_values(form, 'uc_login1$LoginUserName' = 'mymail',
                        'uc_login1$LoginPassword' = 'mypass')
sess_submit <- submit_form(sess, fill_form, submit = "uc_login1$LoginSubmitButton", encoding = "UTF-8")
sudska_praksa <- sess_submit %>%
  jump_to(presude_df$poveznice[1], encoding = "UTF-8")
result <- read_html(sudska_praksa, encoding = "UTF-8") %>%
  html_nodes(xpath = "//*[@id='mainContent']")
odluka_tekst_i_html <- paste(as.character(odluka_tekst_i), collapse = "\n")

但是我无法在python中重现它。我尝试使用请求库:

s = requests.Session()
t = s.get("http://www.sudacka-mreza.hr/sudska-praksa.aspx", auth=HTTPBasicAuth('mymail', 'mypass'))
doc_i = s.get("http://www.sudacka-mreza.hr/odluke.aspx?Search=&Search2=&Court=112&Type=---&Type1=---&Type1a=---&Type2=---&Type2a=---&Type3=&Type4=&O1=&O2=&O3=&O4=&P1=&P2=&ShowID=21216")

,但不会返回正确的页面。你能帮忙吗?

0 个答案:

没有答案