【问题标题】:Python requests-html: Render html with cookiesPython requests-html:使用 cookie 渲染 html
【发布时间】:2020-09-15 14:02:19
【问题描述】:

我想要做什么:

from requests_html import HTMLSession

with HTMLSession() as s:
    s.get('url', cookies=my_cookie_jar)
    s.html.render()
    print(s.html.html)

我想访问需要登录的页面。我已经使用 selenium 浏览器登录,然后将 cookie 导出为 RequestsCookieJar

现在,当我打印 get-request 返回的文本时,我收到了正确网页的文本(但没有呈现 javescript),但是一旦我呈现 html,cookie 似乎就没有效果,我得到了要求我登录的页面的 html(与最初在没有 cookie 的情况下发出请求时得到的相同)。

现在我的问题是:
是否可以在渲染 html 时指定 cookie(或者 requests-html 是否应该默认已经这样做了)?

【问题讨论】:

    标签: python python-requests-html


    【解决方案1】:

    是的,你可以,通过在 render 方法中使用 kwarg cookie。

    s.html.render(cookies=my_cookie_jar)
    

    【讨论】:

    • 得到TypeError: HTML.render() got an unexpected keyword argument 'cookies'
    猜你喜欢
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    相关资源
    最近更新 更多