想爬点基因的突变信息,先研究链接格式:https://www.ncbi.nlm.nih.gov/clinvar/?term=UBR5%5Bgene%5D
UBR5是测试的基因名称。那么我们准备一个基因list就可以了:gene.list。
代码:
import sys,os,re
import time
import shutil
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import Thread
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
我们利用selenium自带的firefox浏览器,首先要做好配置:
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.dir', '/tmp/mozilla_baowenjuan0')
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', '/tmp/mozilla_baowenjuan0')
option = webdriver.FirefoxOptions()
option.add_argument('--headless') #要用无头的哦~
dr = webdriver.Firefox(options=option,firefox_profile=profile)
然后我们观察网页,看怎么定位:
第一步:按照格式输入链接;
第二步:点击Pathogenic这个;
第三步:点击Download(出现悬浮框);
第四步:点击Create File(就会自动下载啦)


link='https://www.ncbi.nlm.nih.gov/clinvar/?term=UBR5%5Bgene%5D'
dr.get(link)
dr.find_element_by_xpath("//a[@data-value_id='Pathogenic']").click() #这样页面就只显示有害的位点了

dr.find_element_by_xpath("//*[@sourcecontent='send_to_menu' and @class='tgt_dark']").click()

dr.find_element_by_xpath("//button[@name='EntrezSystem2.PEntrez.clinVar.clinVar_Entrez_ResultsPanel.Entrez_DisplayBar.SendToSubmit' and @cmd='File']").click()
这样就下载文件了哟~
把以上代码封装为一个函数,就可以循环跑起来了哟~
网友评论