Python-从 asp.net AJAX 应用程序获取数据

发布于 2024-07-18 14:12:08 字数 782 浏览 2 评论 0原文

使用Python,我尝试读取 http://utahcritseries.com/RawResults.aspx 上的值。 我可以很好地阅读该页面,但很难更改年份组合框的值以查看其他年份的数据。 如何读取除默认 2002 年以外的年份的数据?

一旦年份组合框发生更改,该页面似乎正在执行 HTTP Post。 该控件的名称是 ct100$ContentPlaceHolder1$ddlSeries。 我尝试使用 urllib.urlencode(postdata) 为该控件设置一个值,但我一定做错了什么——页面上的数据没有改变。 这可以用 Python 完成吗?

如果可能的话,我宁愿不使用 Selenium。

我一直在使用这样的代码(来自 stackoverflow 用户 dbr),

import urllib

postdata = {'ctl00$ContentPlaceHolder1$ddlSeries': 9}

src = urllib.urlopen(
    "http://utahcritseries.com/RawResults.aspx",
    data = urllib.urlencode(postdata)
).read()

print src

但似乎提取了相同的 2002 年数据。 我尝试过使用 firebug 来检查标头,并且看到很多无关且看起来随机的数据来回发送 - 我是否也需要将这些值发布回服务器?

Using Python, I'm trying to read the values on http://utahcritseries.com/RawResults.aspx. I can read the page just fine, but am having difficulty changing the value of the year combo box, to view data from other years. How can I read the data for years other than the default of 2002?

The page appears to be doing an HTTP Post once the year combo box has changed. The name of the control is ct100$ContentPlaceHolder1$ddlSeries. I try setting a value for this control using urllib.urlencode(postdata), but I must be doing something wrong-the data on the page is not changing. Can this be done in Python?

I'd prefer not to use Selenium, if at all possible.

I've been using code like this(from stackoverflow user dbr)

import urllib

postdata = {'ctl00$ContentPlaceHolder1$ddlSeries': 9}

src = urllib.urlopen(
    "http://utahcritseries.com/RawResults.aspx",
    data = urllib.urlencode(postdata)
).read()

print src

But seems to be pulling up the same 2002 data. I've tried using firebug to inspect the headers and I see a lot of extraneous and random-looking data being sent back and forth-do I need to post these values back to the server also?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

執念 2024-07-25 14:12:08

使用优秀的 mechanize 库:

from mechanize import Browser

b = Browser()
b.open("http://utahcritseries.com/RawResults.aspx")
b.select_form(nr=0)

year = b.form.find_control(type='select')
year.get(label='2005').selected = True

src = b.submit().read()
print src

Mechanize 可在 PyPI 上使用:easy_install mechanize

Use the excellent mechanize library:

from mechanize import Browser

b = Browser()
b.open("http://utahcritseries.com/RawResults.aspx")
b.select_form(nr=0)

year = b.form.find_control(type='select')
year.get(label='2005').selected = True

src = b.submit().read()
print src

Mechanize is available on PyPI: easy_install mechanize

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文