Чтобы получить значение ' Прямой праймер ', ' Обратный праймер ' и ' Длина продукта ' из Primer pair 1
Индуцируйте WebDriverWait()
и visibility_of_element_located
() и далее XPath
.
1.Создать список элементов, а затем выполнить итерацию.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
product_list=['Forward primer','Reverse primer','Product length']
driver=webdriver.Chrome()
driver.get("https://www.ncbi.nlm.nih.gov/tools/primer-blast/primertool.cgi?ctg_time=1585700551&job_key=9P4rCho2F54woA2lAMUpl3reOKVXzSO4Vg&CheckStatus=Check")
for item in product_list:
print(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//h2[text()='Primer pair 1']/following::table[1]//th[text()='{}']/following-sibling::td[1]".format(item)))).text)
Вывод :
GAGGGCATACCCCTCGTAGA
CTGCCGTTTTCCGTAGGACT
506
Чтобы получить данные из всех пар праймеров, попробуйте это.
1.Создайте список праймеров и затем выполните итерацию.
2.Создайте список элементов и затем повторите.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver=webdriver.Chrome()
driver.get("https://www.ncbi.nlm.nih.gov/tools/primer-blast/primertool.cgi?ctg_time=1585700551&job_key=9P4rCho2F54woA2lAMUpl3reOKVXzSO4Vg&CheckStatus=Check")
list_primerpairs=['Primer pair 1','Primer pair 2','Primer pair 3','Primer pair 4','Primer pair 5']
product_list=['Forward primer','Reverse primer','Product length']
for primer in list_primerpairs:
print(primer)
print("===========================================")
for item in product_list:
print(WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.XPATH,"//h2[text()='{}']/following::table[1]//th[text()='{}']/following-sibling::td[1]".format(primer,item)))).text)
print("==========================================")
Вывод :
Primer pair 1
===========================================
GAGGGCATACCCCTCGTAGA
CTGCCGTTTTCCGTAGGACT
506
==========================================
Primer pair 2
===========================================
AGTCCTACGGAAAACGGCAG
GCTATTCTCGCAGCTCACCA
621
==========================================
Primer pair 3
===========================================
AGGTAGTCAGTCAGGTCCCG
TGCCGTTTTCCGTAGGACTC
558
==========================================
Primer pair 4
===========================================
AGGGCATACCCCTCGTAGAT
TCTGCCGTTTTCCGTAGGAC
506
==========================================
Primer pair 5
===========================================
GGGCATACCCCTCGTAGATG
GCCGTTTTCCGTAGGACTCT
502
==========================================
Надеюсь, это поможет.