FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Malformed field path #178

Open ssanders opened 10 years ago

ssanders commented 10 years ago

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Malformed field path "repairBidRelatedByAssetIdentifierList[0].selectWholeBidFlag"' in phar:///mnt/web/public_html/lib/goutte/goutte.phar/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/FormFieldRegistry.php:211 Stack trace: 0 phar:///mnt/web/public_html/lib/goutte/goutte.phar/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/FormFieldRegistry.php(34): Symfony\Component\DomCrawler\FormFieldRegistry->getSegments('repairBidRelate...') 1 phar:///mnt/web/public_html/lib/goutte/goutte.phar/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Form.php(279): Symfony\Component\DomCrawler\FormFieldRegistry->add(Object(Symfony\Component\DomCrawler\Field\InputFormField)) 2 phar:///mnt/web/public_html/lib/goutte/goutte.phar/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Form.php(467): Symfony\Component\DomCrawler\Form->set(Object(Symfony\Component\DomCrawler\Field\InputFormField)) 3 phar:///mnt/web/public_html/lib/goutte/goutte.phar in phar:///mnt/web/public_html/lib/goutte/goutte.phar/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/FormFieldRegistry.php on line 211

larowlan commented 10 years ago

Can you paste the calling code. Can you confirm the crawled page is valid markup.

ssanders commented 10 years ago
$form = $crawler->filter('form')->form();
<input type="hidden" name="repairBidRelatedByAssetIdentifierList[0].selectWholeBidFlag" value="true">
larowlan commented 10 years ago

I think this might be an issue in DomCrawler, not Goutte. However not sure on the use of . in the field name - from PHP manual

Note:

Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"]. 
ssanders commented 10 years ago

This seems to help:

$html = $crawler->html();
$html = str_replace('[', '%5B', $html);
$html = str_replace(']', '%5D', $html);
$crawler->clear();
$crawler->add($html);
David-Kurniawan commented 9 years ago

i have same issue

i cannot submit form if name using this

  $search['guestTypes[0].amount']='1';

always get error:

Malformed field path "guestTypes[0].amount" i try using:

    $html = $crawler->html();
    $html = str_replace('[', '%5B', $html);
    $html = str_replace(']', '%5D', $html);
    $crawler->clear();
    $crawler->add($html);

but iam not lucky...

someone help me please...