使用python提交离线表单 [英] Submitting offline forms using python
问题描述
我正在尝试使用python从我的大学网站中提取信息。这是网站的链接。
http://studzone.psgtech.edu/CommonPage.aspx
我在本地保存了考试成绩页面。我想知道如何使用本地文件提交数据并使用python获取结果页面。我查看了urllib2,请求,机械化框架。但是没有从本地HTML文件提交数据的任何有用信息。在此先感谢。
我使用以下代码获取网页并将其存储在对象中。反正是否有在页面变量中存储的网页中发布表单?我可以编辑字段,使得value =something。
import urllib2
import requests
page = urllib2.urlopen( http://google.com/)。read()
c = requests.post(page,data)# 是这样的吗?
< blockquote>当然。请参阅:
https://docs.python.org/2/howto/urllib2。 html [ ^ ]
或
https://docs.python.org/2/ library / httplib.html [ ^ ]
寻找与POST相关的部分...
尽管如此,在你做这个之前,你可能需要调查http流量。您可能需要模仿更多的浏览器操作,而不仅仅是发布。您可能需要添加会话状态,登录等。 Fiddler [ ^ ]是一个很好的工具。
I am trying to extract information from my college website using python. Here is the link of the website.
http://studzone.psgtech.edu/CommonPage.aspx
I have the exam results page locally saved. I want to know how to submit data using the local file and get the resulting page using python. I've looked into urllib2, requests, mechanize frameworks. But haven't got any useful information on submitting data from a local HTML file. Thanks in advance.
I've use following code to obtain the web page and store it in a object. Is there anyway to post the form in that webpage stored in the page variable? I can edit the field such that value="something".
import urllib2
import requests
page = urllib2.urlopen("http://google.com/").read()
c = requests.post(page, data) #is something like this possible?
Of course. See:
https://docs.python.org/2/howto/urllib2.html[^]
or
https://docs.python.org/2/library/httplib.html[^]
Look for POST related sections...
Still, before you can do this, you might need to investigate http traffic. You might need to mimic more browser action, than just posting. You might need to add session state, log in, and so on. Fiddler[^] is a good tool to start with.
这篇关于使用python提交离线表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!