I need to access a few HTML pages through a Python script, problem is that I need COOKIE functionality, therefore a simple urllib HTTP request won't work.
Any ideas?
In this tutorial, you'll learn how to use Python's simpy framework to create virtual simulations that will help you solve problems like these. In this tutorial, you'll learn how to: Use a simulation to model a real-world process. Create a step-by-step algorithm to approximate a complex system.
Python might be the most popular programming language in the world, but unlike other frontrunner JavaScript, you can't run Python code in the browser.
Pyscript is in alpha and is not production-ready, but Wang did feel it was ready enough to demo during his keynote at PyCon 2022.
Why don't you try Dryscrape for this:
Import dryscrape as d
d.start_xvfb()
Br = d.Session()
Br.visit('http://URL.COM')
#open webpage
Br.at_xpath('//*[@id = "email"]').set('[email protected]')
#finding input by id
Br.at_xpath('//*[@id = "pass"]').set('pasword')
Br.at_xpath('//*[@id = "submit_button"]').click()
#put id of submit button and click it
You don't need cookie lib to store cookies just install Dryscrape and do it in your style
check out Mechanize. "Stateful programmatic web browsing in Python".
It handles cookies automagically.
import mechanize
br = mechanize.Browser()
resp = br.open("http://www.mysitewithcookies.com/")
print resp.info() # headers
print resp.read() # content
mechanize also exposes the urllib2 API, with cookie handling enabled by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With