我的大多数类名都是相同的,我无法提取特定信息。
<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/