代码之家  ›  专栏  ›  技术社区  ›  BlueTrin

使用Python/mechanize select_form()时出错?

  •  2
  • BlueTrin  · 技术社区  · 16 年前

    我正试图从网站上删除一些数据。

    http://www.atpworldtour.com/Rankings/Singles.aspx
    

    应模拟用户通过每个选项获得额外排名和日期,并模拟点击Go,然后在获取数据后应使用back功能。

    目前,我一直在尝试选择此选项作为附加站姿:

                <option value="101" >101-200</option>
    

    from mechanize import Browser
    from BeautifulSoup import BeautifulSoup
    import re
    import urllib2
    
    
    
    br = Browser();
    br.open("http://www.atpworldtour.com/Rankings/Singles.aspx");
    br.select_form(nr=0);
    br["r"] = "101";
    
    response = br.submit();
    

    这是Python返回的日志:

    >>> from mechanize import Browser
    >>>
    >>> from BeautifulSoup import BeautifulSoup
    >>> import re
    >>> import urllib2
    >>>
    >>>
    >>>
    >>> br = Browser();
    >>> br.open("http://www.atpworldtour.com/Rankings/Singles.aspx");
    <response_seek_wrapper at 0x311bb48L whose wrapped object = <closeable_response
    at 0x311be88L whose fp = <socket._fileobject object at 0x0000000002C94408>>>
    >>> br.select_form(nr=0);
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "build\bdist.win-amd64\egg\mechanize\_mechanize.py", line 505, in select_
    form
      File "build\bdist.win-amd64\egg\mechanize\_html.py", line 546, in __getattr__
      File "build\bdist.win-amd64\egg\mechanize\_html.py", line 559, in forms
      File "build\bdist.win-amd64\egg\mechanize\_html.py", line 228, in forms
    mechanize._html.ParseError
    

    我在mechanize主页上找不到对所有功能的正确解释。有人能给我指出一个关于使用表单和机械化的正确教程,或者在这个问题上帮助我吗?

    3 回复  |  直到 16 年前
        1
  •  1
  •   Duane J    16 年前

    http://flashcarddb.com/login )并且不会引发错误。

        2
  •  1
  •   Greg Snowhare    15 年前

    我也遇到了同样的问题。我访问的页面通过了W3C验证,所以我认为这不是标记问题。然而,HTMLTidy抱怨该页面在一个范围内有一个错误。一旦我修好了,mechanize就开始工作了。

    另外,我在邮件列表上看到了对这个问题的回复。我只想指出,将factory=mechanize.RobustFactory()添加到mechanize.Browser()不会改变结果。

        3
  •  0
  •   Yuda Prawira David Dehghan    15 年前

    提示:定义有关mechanize.Browser()的更多信息