使用 Selenium 抓取 React 表 [英] Scraping a React-table using Selenium

查看:44
本文介绍了使用 Selenium 抓取 React 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个代码,用于使用 python selenium 对 HTML React 表进行转义.但它无法捕获表中的值(仅限 DOM 元素).这是网站 https://nonfungible.com/market/history/decentraland?filter=saleType%3D&length=10&sort=blockTimestamp%3Ddesc&start=0这是我的代码:

I have written a code for scaping an HTML React table by using python selenium. But it cannot catch values in the table(only DOM elements). Here is the website https://nonfungible.com/market/history/decentraland?filter=saleType%3D&length=10&sort=blockTimestamp%3Ddesc&start=0 Here is my code:

from selenium import webdriver
dr = webdriver.PhantomJS(r'PATH_TO_PHANTOM/phantomjs-2.1.1-macosx/bin/phantomjs')
dr.get("https://nonfungible.com/market/history/decentraland?filter=saleType%3D&length=10&sort=blockTimestamp%3Ddesc&start=0")
table = dr.find_elements_by_class_name("rt-tr-group")
for item in table:
    headers = ",".join([th.text for th in item.find_elements_by_class_name("rt-td")])
    print(headers)

它什么也不打印.

感谢您的帮助!

推荐答案

如果您打算使用 ChromeDriver 您可以使用以下 定位器策略:

If you intend to use ChromeDriver and google-chrome you can use the following Locator Strategy:

  • 代码块:

  • Code Block:

driver.get("https://nonfungible.com/market/history/decentraland?filter=saleType%3D&length=10&sort=blockTimestamp%3Ddesc&start=0")
print([my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.rt-tr-group div.rt-td")))])

  • 控制台输出:

  • Console Output:

    <代码> [ 'LAND', '115792089237316195423570985008687907834894736851909887012435355206597646221309', '', '', '', '$ 798.462','20,000(MANA) '' 1小时前2020年7月14日,12点23分58秒PM ' 'DCLENS', '43469741616618090506261857019714019688977185639939981493731790027408795972144', '', '', '', '$ 13.141', '333(MANA)', '3个小时前2020年7月14日,上午10时48分46秒','DCLENS ' '89838368294314845493020349053893353532486044687731983038462074466093608387295', '', '', '', '$ 11.627', '295(MANA)', '3个小时前2020年7月14日,上午10点44分24秒', 'DCLENS','25527909519625043332149265050323189196974713653740181118935970777552699458072' , '', '', '', '$ 4.035', '100(MANA)', '5小时前2020年7月14日,上午08时23分03秒', 'DCLXMAS2019', '349','', '', '', '$50.91', '1,251 (MANA)', '7 小时前 7/14/2020, 6:11:31 AM', 'LAND', '13611294676837538538537278429', '87829', '', '$897.357', '22,000 (MANA)', '9 小时前 7/14/2020, 4:48:01 AM', 'DCLLNCH', '3629', '', '', '','$8.164', '200 (MANA)', '10 小时前 7/14/2020, 3:04:35 AM', 'LAND', '115792089237316195423570985008687907837276713420356456256678977458620023701615' , '', '', '', '$ 609.161','14,960(MANA) ''11小时前2020年7月14日,上午02时38分29秒', 'DCLENS', '93012029374970918876221125714905812452590679293106342049263811906231821801921','', '', '', '$4.086', '100 (MANA)', '12 小时前 7/14/2020, 1:39:25 AM', 'DCLMNSHT2020', '2260', '', '', '', '$19.138', '0.08 (ETH)', '13 小时前 7/14/2020, 1:00:43 AM']

  • 这篇关于使用 Selenium 抓取 React 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆