gpt4 book ai didi

python - 使用 Python 的 Mechanize 提交 Html 表单时出现问题

转载 作者:行者123 更新时间:2023-11-28 16:51:18 26 4
gpt4 key购买 nike

我正在尝试登录网站 http://ogame.us使用 python 访问数据。在网上查看如何尝试执行此操作后,我决定使用 mechanize 模块。我想我已经记下了代码的一般要点,但是当我提交 html 表单时,什么也没有发生。这是代码:

import sys,os
import mechanize, urllib
import cookielib
from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag
import datetime, time, socket
import re,sys,os,mechanize,urllib,time, urllib2


br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6')]
br.open('http://ogame.us')

br.select_form(name = 'loginForm' )

br['login'] = 'stackexample'
br['pass'] = 'examplepassword'
br['uni_url'] = ['uni103.ogame.us']

br.submit()

print br.geturl()

geturl() 的响应与我之前访问的 url 相同。有人知道这是怎么回事吗?

最佳答案

试试这个:

    data = br.submit()
html=data.read()

关于python - 使用 Python 的 Mechanize 提交 Html 表单时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7057631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com