James Draper
James Draper

Reputation: 5310

How to use mechanize in python to input a string into a certain part of a form?

I am trying to use python to submit a large number of amino acids (stored as strings) one at a time to a protein prediction website hosted by ExPasy.org. I would like to store the results for each protein as a list. So far this is what I have;

In[]:
br = mechanize.Browser()
br.open("http://www.expasy.org/proteomics")
response1 = br.follow_link(text_regex=r"TMPred", nr=1)

for i in br.forms():
    print i

From here I can see the forms.

Out[]:
<POST http://embnet.vital-it.ch/cgi-bin/TMPRED_form_parser application/x-www-form-urlencoded
    <SelectControl(outmode=[*html, ascii])>
    <SelectControl(min=[14, 16, *17, 18, 19, 20, 21, 22, 23, 24, 25, 26])>
    <SelectControl(max=[23, 25, 27, 29, 31, 32, *33, 34, 35, 37, 39, 41])>
    <TextControl(comm=)>
    <SelectControl(format=[*plain_text, READSEQ_convertible, SwissProt_ID, TrEMBL_ID, GenPept_gi, YEAST_ORF])>
    <TextareaControl(seq=)>
    <SubmitControl(<None>=Run TMpred) (readonly)>
    <IgnoreControl(<None>=<None>)>>

I can't figure out how to select the textbox or input my strings into the textbox. I know that there has to be a simple solution out but for some reason I can't find anything out there that works. Also if anyone out there has a simpler solution please let me know. Thanks!

Upvotes: 2

Views: 537

Answers (1)

falsetru
falsetru

Reputation: 368944

Input, select, textarea tags has name. Use that name.

For example, the Input sequence format select tag has name format:

br.select_form()  # <----- pick a form
br['format'] = 'plain_text'

Upvotes: 1

Related Questions