问题描述:

When I write address of a website in my browser address bar and click on Go, a packet such as below sends out by the browser :

GET / HTTP/1.1

Host: stackoverflow.com

User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Cookie: __qca=P0-1436433254-1422702693572; sgt=id=e2dfc663-bf2a-4c13-9387-91db3c901b72; usr=t=5Or7fZxDxUa8&s=xyx0L95dfE61; acct=t=OzuSyto294xCVVgU1B2tOow2C%2bSXqT0m&s=WmMKQ3H9NtZs%2b4%2bfbSnoLretaRnysYju; _ga=GA1.2.1042841397.1422702694

Connection: keep-alive

I catch the above packet using BurpSuite tool and it is a request for StackOverflow.com

Now I want to know is there any way to automate this request with python?

In the other word, I want to send the above packet with a Python script, and receive the answer in browser (Chrome for example). Is it possible?

Note:

I want to modify the packets also. I don't want to send a simple website request only. I want to change some parts of the request packets also. For example in some packets, there is a parameter named challenge, And I want to send request for a website with different challenges. Moreover, assume that I want to fill a form in a website automatically (Signing up different users for example). (Not exactly by filling the form.By sending the same packet that the browser sends when I click on Sign Up or Confirm for example)

Update :

Actually, I want to do a stress test for a web server. So I want to send a sequence of requests with different headers (i.e. requests for different users) to do a single transaction 1000 times for 1000 different user.Finally I want to see if the transactions done successfully or not. (Assume that the transaction is deposit some money into a single account with different users- So in the end of test I can check the money of that account to see if the transactions done successful or not.) or I can send requests to sign up for different users, and in the end the number of created accounts, will specifies the efficiency of the system in respond of a lot of request.So the response of the web server to my computer is not really important. But if it was possible to see it, It is pleasure

网友答案:

Use Selenium to interact with browsers, you can start with this page and also you can read the docs.

Below code is a simple usage of selenium:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")

try this and enjoy...

相关阅读:
Top