Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OR selectors together #1

Open
amccloud opened this issue Oct 31, 2009 · 1 comment
Open

OR selectors together #1

amccloud opened this issue Oct 31, 2009 · 1 comment

Comments

@amccloud
Copy link

One of the features that I wanted to suggest is some sort of logical OR operator.

For example,
http://www.bestbuy.com/site/Swiss+Gear+-+SHERPA+Laptop+Sleeve+-+Black/Blue/8819264.p?skuId=8819264&id=1206750211247

I want the price. I'd like to have the sale price and if none is provided the original price. I've tried 3 diff ways to achieve this. The first, which I believe would probably be the best syntax for this to be implemented, comma delimited selectors.

{ "price": "#productpreview .salenum, #productpreview .pricenum" }

Then I tried
{ "price?": "#productpreview .salenum", "price": "#productpreview .pricenum" }

finally because my crawling software (Scrapy) takes the first object from the list
{ "price": ["#productpreview .salenum, #productpreview .pricenum"] }

... but order is not preserved so that isn't reliable. If order was preserved this would be my second choice.

Any thoughts? or has this already been implemented?

Andrew

@fizx
Copy link
Owner

fizx commented Nov 2, 2009

Right, so the logical OR operators (css comma or pipe in xpath), maintain order, but with respect to the page. So the original price will always come first, because it's higher on the page.

This is getting to be a little to much logic for Parsley, which was never designed to be Turing-complete. I can see implementing a reverse() function, which would give you a workaround here. My approach to this problem is reflected in the csvget project, where each row is optionally post-processed in Ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants