How to use Selniunhq to fill out forms with php?

Asked

Viewed 1,145 times

1

I am days without sleep.. rs , trying to solve a problem that seemed simple to me... I have data in a database and I need to fire that data to another site by filling out the oriúndos fields of the database and submitting... I was trying to do with Curl, but a colleague told me that the correct thing is to do with seleniunHQ, does anyone know how to use seleniun to automate the registration of a form as if it were a robot? This job is to serve an agency, where I have to collect the data of a page Landing and popular other...

1 answer

2


Your question is very broad, however I will try to help you.

You can use a combination of: Python + Selenium to browse and populate the forms. If you need to gather information from open pages, you can also use the library BeautifulSoup to extract the Infos.


To launch the browser:

driver = webdriver.Chrome()

To open a URL:

driver.get("www.url.com")

To find and fill in a field with the value "MeuNome":

text = driver.find_element_by_xpath('//input[@id="primeiro_nome"]')
text.send_keys('MeuNome')

To press the continue button:

button = driver.find_element_by_xpath('//input[@id="btn_continuar"]')
button.click()

To collect data from a page, you can create a soup with the contents of the open page on the Selenium webdriver:

html_source = driver.page_source
soup = BeautifulSoup(html_source, 'lxml')

After creating a database with the information to be filled in, you can create a repeat structure to fill the pages with each iteration:

for reg in registros:
    nome = reg[0]
    sobrenome = reg[1]
    aniversario = reg[2]
    nickname = reg[3]

    abre_pagina()

    preenche_dados()

    finaliza_cadastro()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.