0

I have right boundary of div class=product-item data-productid=and a left boundary of > How can I perform correlation in locust.

response.text does give me the entire response but I need to extract the value from the above boundaries

How to do that?

Tester
  • 53
  • 2
  • 7

1 Answers1

0

There are many options.

You can parse and then query the html document using XPath, for example using LXML (https://docs.python-guide.org/scenarios/scrape/).

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()')

(I have not tested this code :)

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)
Cyberwiz
  • 11,027
  • 3
  • 20
  • 40