Python(Post)提交表单

时间:2015-06-02 19:18:42

标签: python post submit

我正在教自己在网上提交表格

但不知何故帖子不起作用。

网址为https://courselist.wm.edu/courselist/

目前的代码是:

from bs4 import BeautifulSoup
import requests
import urllib
import re

url = 'http://courselist.wm.edu/courselist'
with requests.Session() as session:

   response = session.get(url)
   soup = BeautifulSoup(response.content)

   data = {
      'term_code' : '201530',
      'term_subj' : 'AFST',
      'attr' : '0',
      'levl' : '0',
      'status' : '0'
   }

   r = session.post(url, data=data)

   #response = session.post(url, data=data)
   print r.content
   #soup = BeautifulSoup(response.content)

   #for row in soup.select('table'):
     # print [td.text for td in row.find_all('td')]

1 个答案:

答案 0 :(得分:0)

您无法使用 Beautifulsoup 提交表单。为此,您应该使用Mechanize。请参阅here如何将其用于表单提交的示例。