3 回答
TA贡献1812条经验 获得超5个赞
尝试以下操作
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.ncbi.nlm.nih.gov/tools/primer-blast/primertool.cgi?ctg_time=1585700551&job_key=9P4rCho2F54woA2lAMUpl3reOKVXzSO4Vg&CheckStatus=Check")
time.sleep(2)
pair_1 = driver.find_element_by_css_selector(
"#alignments > div:nth-child(1) > table > tbody > tr:nth-child(2) > td:nth-child(2)"
).get_attribute("innerHTML")
print(pair_1)
在 Windows 上,chrome 版本 80
选择文本>右键单击>检查>右键单击>检查>右键单击<td>复制选择器
TA贡献1810条经验 获得超4个赞
从Induce和()中得到“正向引物”、“反向引物”和“产物长度”的值。Primer pair 1WebDriverWait()visibility_of_element_locatedXPath
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
==========================================
希望这可以帮助。
TA贡献1859条经验 获得超6个赞
尝试以下代码:
driver.get('https://www.ncbi.nlm.nih.gov/tools/primer-blast/primertool.cgi?ctg_time=1585700551&job_key=9P4rCho2F54woA2lAMUpl3reOKVXzSO4Vg&CheckStatus=Check')
str1 = "Primer pair 1";
str2 = "Forward primer";
el = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h2[text()='" +str1 +"']//following-sibling::table//th[text()='" +str2+"']//following-sibling::td[1]")))
print(el.text)
您可以更改字符串值。
出现此错误TypeError: 'str' object is not callable是因为您在这一行中出错:
pair_1 = driver.find_element(By.XPATH("the value"))
它应该:
pair_1 = driver.find_element(By.XPATH, "the value")
- 3 回答
- 0 关注
- 126 浏览
添加回答
举报