Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests, urllib
- ### Getting contents from a site very simple
- result = requests.get( "https://icanhazip.com" )
- print result.text
- ### Getting contents from a site with headers
- # Easier to read the code when it's formatted
- result = requests.get(
- "https://icanhazip.com",
- headers={
- "Some-Header-Here": "Some-Value-Here",
- "User-Agent": "Requests/Python"
- }
- )
- ### POSTING data used when submitting a form like logging in/signup etc
- result = requests.post(
- "https://sitetologin.com/login",
- headers={
- "User-Agent": "User-agent (important)"
- },
- data=urllib.urlencode({
- "username": "username123",
- "password": "password123"
- })
- )
- if result.text == "success":
- print "we logged in fine!"
- else:
- print "No! site didn't return success"
- #### Proxies
- result = requests.get(
- "https://icanhazip.com",
- proxies={
- "https": "https://PROXY:PORT"
- }
- )
- print result.text #should respond with the proxies ip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement