2

I need to get a ul tag by the class name but the class name has a lot of different combinations but it is always just two letters that changes. product-gallerytw__thumbs could be one and product-galleryfp__thumbs could be one. I need to know how to use a css selector that uses regex so that either of these could be found (or any other combination)

I can't use Xpath as the location changes

img_ul = response.css('.product-gallerytw__thumbs')
        
print(img_ul)

This is what I am trying to do but have not found a way to add regex inside the .css()

1 Answer 1

2

You actually can use xpath:

img_ul = response.xpath("//*[contains(@class,'product-gallery')]")

or if you really need to specify everything but the two characters:

img_ul = response.xpath("//*[contains(@class,'product-gallery')][contains(@class,'__thumbs')]")

There is nothing a css selector can do that xpath can't. In fact css selectors are simply an abstraction of xpath selectors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.