Python dryscrape 用 cookie 刮页面 [英] Python dryscrape scrape page with cookies

查看:33
本文介绍了Python dryscrape 用 cookie 刮页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从站点获取一些数据,这需要登录.
我通过请求

I wanna get some data from site, which requires loggin in.
I log in by requests

url = "http://example.com"
response = requests.get(url, {"email":"a@gmail.com", "password":"12345"})
cookies = response.cookies

然后我想从某个 JS 页面获取数据.通过请求这是不可能的,所以我必须使用dryscrape.

Then I wanna get data from some JS page. Through requests it isn't possible, so I have to use dryscrape for this.

import dryscrape
url = "http://example.com/js-page"
sess = dryscrape.Session()
sess.visit(url)

是否可以将 cookie 传递给 visit() 或者我必须寻找其他解决方案?

Is it possible to pass cookies to visit() or I have to look for another solution?

推荐答案

为什么不用dryscrape登录?

Why not login by dryscrape?

session = dryscrape.Session()
session.visit('<url_where_is_login_form>')
name = session.at_xpath('//*[@name="username"]') # Where <input name="username">
name.set("<login>")
password = session.at_xpath('//*[@name="password"]') # Where <input name="password">
password.set("<password>")
# Push the button
name.form().submit()
session.visit("<url to visit with proper cookies>")

这篇关于Python dryscrape 用 cookie 刮页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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