2010-05-21 3 views

답변

5

forms reference에는 response 개의 개체에 텍스트 컨트롤을 채우는 몇 ​​가지 예가 있습니다.

관련 인용 :

# The kind argument can also take values "multilist", "singlelist", "text", 
# "clickable" and "file": 
# find first control that will accept text, and scribble in it 
form.set_value("rhubarb rhubarb", kind="text", nr=0) 

kind 인수는 "text" 컨트롤을 찾습니다 form.find_control()form.set_value() 방법을 사용할 수 있습니다.

mechanize _form.py source에 약간 파고 설명이 있습니다. 기계화 TextControlTEXTAREA 양식 요소를 포함합니다.

#--------------------------------------------------- 
class TextControl(ScalarControl): 
    """Textual input control. 

    Covers: 

    INPUT/TEXT 
    INPUT/PASSWORD 
    INPUT/HIDDEN 
    TEXTAREA 

    """ 
    def __init__(self, type, name, attrs, index=None): 
     ScalarControl.__init__(self, type, name, attrs, index) 
     if self.type == "hidden": self.readonly = True 
     if self._value is None: 
      self._value = "" 

    def is_of_kind(self, kind): return kind == "text" 
6

당신은 br['term'] = "Mechanize"는 관련 라인

import mechanize 

br = mechanize.Browser() 
br.open("http://pypi.python.org/pypi") 
br.select_form("searchform") 
br['term'] = "Mechanize" 
response = br.submit() 

과 같은 작업을 수행 할 수 있습니다.

그리고 질문에 대한 답변을 심각하게 받아 들여야합니다. 당신이 첫 번째 요소의 형태를 검사 할 수 있습니다

1

과 페이지의 많은 형태

for form in br.forms(): 
    print form 
와 함께 할 수있는 방법
관련 문제