当所有类都具有相似的名称时,如何在selenium python中提取数据?
我大部分的类名都是一样的,我无法提取具体的信息当所有类都具有相似的名称时,如何在selenium python中提取数据?,python,python-3.x,selenium,selenium-webdriver,jupyter-notebook,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)
<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>
如何获得它?您可以按照下面提到的方法获得所需的输出 代码:
# 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
有几次出现了
,但是您想要的那一个有特定的文本Publisher
,因此您应该能够很容易地找到它。你试过什么?
# 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