doukanhua0752 2019-07-14 08:13
浏览 514
已采纳

如何处理php-webdriver中“陈旧元素引用:元素未附加到页面文档”错误中的致命错误?

I need to read ask/bid price from crytpocurrency market. but "Stale Element Error" occurred when market is too crowd.

I use facebook/php-webdirver, Selenium Stand Alone Server 3.9.1.jar and chromeDriver and PHP 7.1 .

this is my first try to select data:

$driver->findElements(WebDriverBy::xpath("//tr[@class='price-level']//td[@class='bid-price']"));

and its the last one:

$driver->wait()->until(WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(WebDriverBy::xpath("//tr[@class='price-level']//td[@class='bid-price']")));

First question is am I in a right way to get this rapidly changeable data (like stock market or cryptocurrencies market)? cryptocurrency BID-ASK tables screenshot - from Bitz Bitz Cryptocurrency live BID-ASK table

And the second one is why when i use below Code to avoid fatal Error, nothing happened and fatal Error occurred as always ?

try{
$asks = $driver->findElements(WebDriverBy::xpath("//tr[@class='price-level']//td[@class='ask-price']"));
}catch(StaleElementReferenceException $e)
{
echo 'Error Occurred';
}
  • 写回答

1条回答 默认 最新

  • dongying9712 2019-07-19 07:56
    关注

    Finally after spend more than a week on Php, i decided to change my way. I review other language approaches. Js was first in weekly downloads. i try to use Selenium-WebDriver library in first with more than 1.4 million weekly downloads. Ok but i could not use this. actually i didn't like it for personal reason! also the other famous JS web scraping library named 'WebDriverIO' was not that i wants!

    i never use NodeJS and NPM before and i cant find Quick install or fast way to run it and being professional.

    I try Python for second and results was Great :) there is very fast start, many readable document to find your goal and many person to answer your question in other hand Python syntax was too similar to Php and you can connect it MySQL as easy you ever done in Php.

    Python 3.7 with Selenium for python helped me to finish my app under 10 hours ( include learning python from zero).

    finally my app works like a charm and i'm really happy :) now i have and interface coded by HTML/JS(jQueryAjax) + Database Connection on the server to feed my fontend + Python Script to scrape and feel DB.

    Try-Catch still not working in facebook/php-webdriver Php but who care now !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接