如何使用硒刮json元素?

时间:2019-06-02 08:46:09

标签: python selenium beautifulsoup

我需要从json元素中抓取数据。单击该元素会打开一个弹出窗口,其中包含我需要的数据。

我尝试使用硒单击该元素,但是它返回None

driver.find_element_by_link_text('View details').click()

URL-https://play.google.com/store/apps/details?id=in.amazon.mShop.android.shopping

所需的输出-(此应用有权访问: 存储 修改或删除USB存储设备的内容 读取USB存储器中的内容 联络人 阅读您的联系人 在设备上查找帐户 麦克风 录制音频 短信 阅读短信(短信或彩信) 接收短信(SMS) 发送短信 照片/媒体/文件 修改或删除USB存储设备的内容 读取USB存储器中的内容 相机 拍照和录像 电话 读取电话状态和身份 身分识别 添加或删除帐户 在设备上查找帐户 Wi-Fi连接信息 查看Wi-Fi连接 位置 精确位置(基于GPS和网络) 大概位置(基于网络) 设备ID和通话信息 读取电话状态和身份 其他 阅读首页设置和快捷方式 从互联网接收数据 防止设备进入睡眠状态 查看网络连接 控制手电筒 在设备上使用帐户 安装捷径 创建帐户并设置密码 连接和断开Wi-Fi 完全网络访问 控制振动 在启动时运行)

这是json元素

This is the json element

其中包含必需的文字 This contains the required text

1 个答案:

答案 0 :(得分:0)

您的lastContentOffset语句在没有上下文的情况下不会告诉我们任何信息,即一段代码,该代码导航到页面并单击链接。该错误可能存在于任何地方。

一些提示:

  1. 始终使用Explicit Waits来等待元素出现,例如:

    tableView

    更多信息:How to use Selenium to test web applications using AJAX technology

  2. 为了获取HTML元素的文本,您可以使用innerText DOM objectget_attribute function属性,例如:

    extension ViewController: UITableViewDelegate {
        func scrollViewDidScroll(_ scrollView: UIScrollView) {
            if scrollView == self.tableView {
                if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
                    //Scrolled to bottom
                    UIView.animate(withDuration: 0.3) {
                        self.collapsingViewHeightConstraint.constant = 0.0
                        self.view.layoutIfNeeded()
                    }
                }
                else if (scrollView.contentOffset.y < self.lastContentOffset || scrollView.contentOffset.y <= 0) && (self.collapsingViewHeightConstraint.constant != 150.0)  {
                    //Scrolling up, scrolled to top
                    UIView.animate(withDuration: 0.3) {
                        self.collapsingViewHeightConstraint.constant = 150.0
                        self.view.layoutIfNeeded()
                    }
                }
                else if (scrollView.contentOffset.y > self.lastContentOffset) && self.collapsingViewHeightConstraint.constant != 0.0 {
                    //Scrolling down
                    UIView.animate(withDuration: 0.3) {
                        self.collapsingViewHeightConstraint.constant = 0.0
                        self.view.layoutIfNeeded()
                    }
                }
                self.lastContentOffset = scrollView.contentOffset.y
            }
        }
    }
    
  3. 就是这样,您应该将所需的文本作为变量:

    enter image description here