PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] Symfony \ Component \ CssSelector \ Exception \ SyntaxErrorException cssselector to xpath in laravel

 February 10, 2022     css-selectors, domcrawler, laravel-5, symfony-css-selector, xpath     No comments   

Issue

I have following html select element, select element's attribute name containing square bracket and need to filter using domcrawler but unfortunately, CssSelectorConvertor() cannot convert cssselector to xpath because of square bracket in the name attribute.

HTML code of another page:

<select name="get_result[our_school_dis]">
    <option value="a">Result 1</value>
</select>

code in laravel controller:

$crawler = $client->request('GET', 'http://anotherpage.com/abc');
$converter = new CssSelectorConverter();
$converter->toXPath('select[name=result[our_school_dis]]');

It throws error as :

Symfony \ Component \ CssSelector \ Exception \ SyntaxErrorException
Expected "]", but <delimiter "[" at 22> found.

looking for appropriate solution

thank you


Solution

For attribute value that contains special character, use quotes in your CSS selector :

$converter->toXPath('select[name="result[our_school_dis]"]');


Answered By - har07
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing