填写请求表并检索

2024-10-02 10:19:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我对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

Tags: brimport信息urlinputrequestsyearduration

热门问题