user19671534
user19671534

Reputation:

Fill in internet form using a pandas dataframe and mechanicalsoup

I am using mechanicalsoup and I need to auto-fill the internet form using information from a dataframe, automatically.

The dataframe is called checkdataframe.

    br = mechanicalsoup.StatefulBrowser(user_agent='MechanicalSoup')
    for row in checkdataframe.codenumber:
       if row in '105701':
          url = "https://www.internetform.com"
          br.open(url)
          for column in checkdataframe[['ID', 'name','email']]:
              br.select_form('form[action="/internetform.com/info.do"]')
              br.form['companycode'] =checkdataframe['ID']  #THIS INFORMATION SHOULD COMING FROM DATAFRAME
              br.form['username'] = checkdataframe['name'] #THIS INFORMATION SHOULD COMING FROM DATAFRAME
              br.form['emailaddress'] = checkdataframe['email'] #THIS INFORMATION SHOULD COMING FROM DATAFRAME
              response = br.submit_selected()
              soup = BeautifulSoup(response.text, 'lxml')

              table = soup.find('div', attrs = {'class':'row'})
              for row in table.findAll('div', attrs = {'class':'col-md-4 col-4'}):
                  scrapeinfo = {}
                  scrapeinfo['STATUS'] = row.div
                  scrapeinfo['NAMEOFITEM'] = row.label
                  scrapeinfo['PRICE'] = row.div
                  checkdataframe.append(scrapeinfo)
        
        
else:
        break

How can I make br.form['companycode'] =checkdataframe['ID'] this work, instead of

br.form['companycode'] = '105701'

br.form['username'] = 'myusername'

br.form['emailaddress'] = '[email protected]'

I need to append the information that is scrape into the checkdataframe. I need help, please.

Upvotes: 0

Views: 106

Answers (1)

user19671534
user19671534

Reputation:

Use selenium for this activity

Upvotes: 0

Related Questions