我对Python非常陌生,这实际上是我的第一个应用程序,所以请耐心等待。我想访问一个特定的网站,填写表格中的信息,并获得POST
表格后的信息。有人可以帮我这个。提前谢谢。
import requests
import mechanize
from bs4 import BeautifulSoup
# set needed variables
br = mechanize.Browser()
url = 'https://www.oanda.com/currency/average'
startMonth = input('Enter Month Number: ')
endMonth = startMonth
year = input('Enter Year: ')
duration = 'Month'
convertAmount = 1
foreignCurrency = 'AED'
domesticCurrency = 'USD'
interBankRate = 0
viewFormat = 'HTML'
payload = { 'amount': convertAmount, 'avg_type': duration,
'start_month': startMonth, 'end_month': endMonth,
'start_year': year, 'end_year': year, 'base': foreignCurrency,
'exchange': domesticCurrency, 'interbank': interBankRate,
'format': viewFormat }
#br.open(url)
#html = br.read()
#print html
# r = requests.get(url)
r = requests.post(url, data=payload)
r.text
print r.text