from bs4 import BeautifulSoup
import requests
from requests.auth import HTTPProxyAuth
url = "http://www.transtats.bts.gov/Data_Elements.aspx?Data=2"
proxies = {"http":"xxx.xxx.x.xxx: port"}
auth = HTTPProxyAuth("username", "password")
r = requests.get(url, proxies=proxies, auth=auth)
soup = BeautifulSoup(r.text,"html.parser")
viewstate_element = soup.find(id = "__VIEWSTATE").attrs
viewstate = viewstate_element["value"]
eventvalidation_element = soup.find(id="__EVENTVALIDATION").attrs
eventvalidation = eventvalidation_element["value"]
data = {'AirportList':"BOS",'CarrierList':"VX",'Submit':'Submit',"__EVENTTARGET":"","__EVENTARGUMENT":"","__EVENTVALIDATION":eventvalidation,"}
r = requests.post(url, proxies, auth, data )
print r
This code works fine when I use requests.get(url, proxies=proxies, auth=auth)
, but what to do when there is some data that has to be sent through requests.post()
under proxy authentication?
On behalf of Vikas Neha Ojha so all can see
proxies = {'http': 'http://username:password@ip:port', 'https': 'http://username:password@ip:port'}
and then
requests.post(url, proxies=proxies, data=data)
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