用python实现自动填入四个网页的表单框中
时间: 2023-05-27 17:03:53 浏览: 176
需要先确定需要填写的表单框的网页链接、表单框所代表的字段、以及对应的值。以下是一个简单的示例代码:
```python
import requests
url1 = 'https://example.com/form1'
url2 = 'https://example.com/form2'
url3 = 'https://example.com/form3'
url4 = 'https://example.com/form4'
data1 = {'name': 'Alice', 'email': 'alice@example.com', 'phone': '123-456-7890'}
data2 = {'username': 'alice', 'password': 'password1234', 'confirm_password': 'password1234'}
data3 = {'address': '123 Main Street', 'city': 'New York', 'state': 'NY', 'zip': '10001'}
data4 = {'age': '30', 'gender': 'Female', 'education': 'Bachelor', 'occupation': 'Engineer'}
response1 = requests.post(url1, data=data1)
response2 = requests.post(url2, data=data2)
response3 = requests.post(url3, data=data3)
response4 = requests.post(url4, data=data4)
if response1.ok and response2.ok and response3.ok and response4.ok:
print("Form submission successful!")
else:
print("Error submitting form.")
```
在上述代码中,使用了Python的Requests库来发送POST请求,将表单数据填入指定的表单框中。请求发送后,可以根据响应的状态码(`response.status_code`)来判断表单提交是否成功。如果状态码为200,则表示提交成功。
阅读全文