简体   繁体   中英

Python dryscrape scrape page with cookies

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

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)

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

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>")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM