python - 当所有类名称相似时,如何在selenium python中提取数据?

标签 python python-3.x selenium selenium-webdriver jupyter-notebook

我的大多数类名都是相同的,我无法提取特定信息。

 <div class="block-record-info">
    <div class="title3">Author Information</div>
    <p class="FR_field">
    <span class="FR_label">Reprint Address: </span>
    Havens, T (reprint author)
    </p>
    <table class="FR_table_noborders" rules="NONE" cellspacing="0" cellpadding="0" border="0">
    <p/>
    <p class="FR_field">
    <span class="FR_label">Addresses:   </span>
    </p>
    <table class="FR_table_noborders" rules="NONE" cellspacing="0" cellpadding="0" border="0">
    <p/>
    </div>
    <div class="block-record-info">
    <div class="title3">Publisher</div>
    <p class="FR_field">
    <value>SOC JAPANESE STUD, UNIV WASHINGTON THOMSON HALL DR-05, SEATTLE, WA 98195 USA</value>
    </p>
    </div>
    <div class="block-record-info">
    <div class="title3">Categories / Classification</div>
    <p class="FR_field">
    <span class="FR_label">Research Areas:</span>
    Area Studies; Asian Studies
    </p>
    <p class="FR_field">
    <span class="FR_label">Web of Science Categories:</span>
    Area Studies; Asian Studies
    </p>
    </div>

我想要这样的输出

Publisher 

SOC JAPANESE STUD, UNIV WASHINGTON THOMSON HALL DR-05, SEATTLE, WA 98195 USA
Research Areas

Area Studies; Asian Studies

Web of Science Categories

Area Studies; Asian Studies

如何获取它?

最佳答案

您可以按照下面提到的方法获得您想要的输出。

代码:

# Print the "Publisher" text.
print driver.find_element_by_xpath("//div[@class='block-record-info']/div[@class='block-record-info'][1]/div").text

# Print the other paragraph text which you have specified in your output.

records = driver.find_elements_by_xpath('//div[@class="block-record-info"]/div[@class="block-record-info"]')

for record in records:
print record.find_element_by_xpath('.//p').text

关于python - 当所有类名称相似时,如何在selenium python中提取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44744079/

相关文章:

java - 如何在 testng extent-report 版本 2.41.2(相关代码)中添加数据提供者值

python - 如何使用 python 代码获得异常大的素数

python - 从 django-rest-framework 应用程序自动发布到 Facebook 页面

python - 字典仅打印并保存最后一项

python - 下载了Python版的SciPy,无法使用

javascript - 使用 Protractor 选择列表中的第二个 anchor 元素

python - 如何在本地测试 Heroku python 应用程序?导入错误: No module named wsgi

python - 如何告诉Python调试器完成程序?

python-3.x - 使用自定义目标/损失函数的随机森林回归器(Python/Sklearn)

c# - 是否可以通过编程方式检查 selenium Remote Webdriver Server 是否正在运行