Python 用请求填写表单并检索信息

Python 用请求填写表单并检索信息,python,beautifulsoup,python-requests,Python,Beautifulsoup,Python Requests,我对Python非常陌生,这实际上是我的第一个应用程序,所以请容忍我。我想去一个特定的网站,填写表格中的信息,并在发布表格后获得任何信息。有人能帮我做这个吗。先谢谢你 import requests import mechanize from bs4 import BeautifulSoup # set needed variables br = mechanize.Browser() url = 'https://www.oanda.com/currency/average' startMo

我对Python非常陌生,这实际上是我的第一个应用程序,所以请容忍我。我想去一个特定的网站,填写表格中的信息,并在
发布
表格后获得任何信息。有人能帮我做这个吗。先谢谢你

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