简体   繁体   English

Python(发布)提交表单

[英]Python (Post) submit a form

I am teaching myself with submitting a form on the web 我正在教自己在网络上提交表格

but somehow post is not working. 但不知何故帖子不起作用。

The url is https://courselist.wm.edu/courselist/ 网址为https://courselist.wm.edu/courselist/

and the code so far is: 到目前为止的代码是:

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')]

You cannot submit a form with Beautifulsoup . 您无法使用Beautifulsoup提交表单。 For this you should use Mechanize . 为此,您应该使用Mechanize See here an example of how to use it for form submitting. 请参阅此处的有关如何使用它进行表单提交的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM