I have earlier used jmeter css selector and XPath extractor post processor to retrieve Csrf token. Is there anyway to use these in locust as well
I want to fetch from value attribute
I have earlier used jmeter css selector and XPath extractor post processor to retrieve Csrf token. Is there anyway to use these in locust as well
I want to fetch from value attribute
You can use LXML FOR XPath
from lxml import html
...
@task
my_task(self):
response = self.client.post(...)
tree = html.fromstring(response.text)
# <div title="buyer-name">Carson Busses</div>
# <span class="item-price">$29.95</span>
buyers = tree.xpath('//div[@title="buyer-name"]/text()')
(example from https://docs.python-guide.org/scenarios/scrape/)
Another option is to use pythons built in HTML parser, but that is probably more complicated for this use case (https://docs.python.org/3/library/html.parser.html)
You could also use a regular expression for a quick and dirty solution:
import re
message_regex = re.compile(r"...") # use a regex that actually matches your desired text
...
@task
my_task(self):
response = self.client.post(...)
m = message_regex.match(response.text)
my_value = m.group(1)
I have used pyquery to fetch value attribute using css selector and xpath
First we need to import pyquery
from pyquery import PyQuery as pq
for css selector
response = self.client.get("/edtwrkkd?id=251612")
tree=pq(response.text)
Test=tree("#formTest")
self.Token=Test("input[name='__RequestVerificationToken']").val()
for xpath
Test =tree("form[method='post']")
self.Token=Test("input[name='__RequestVerificationToken']").val()