Python Selenium.text仅返回部分文本

2024-05-20 16:05:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用selenium webelements中的.text函数从网站上的一个简单文本块中检索文本。所讨论的文本位于<pre>个HTML标记之间。问题是该函数只返回一定长度的文本(大约56行文本)。网站上的文本量接近1250行,但只返回前56行左右。我在这里使用Firefox webdriver

有关职能如下:

web_text = driver.find_element_by_xpath("//pre")
    output_text = web_text.text
    print(output_text)
    return(output_text)

到目前为止,我已经尝试使用get_attribute()及其各种文本属性。有什么想法吗


Tags: 函数text标记文本weboutput网站html
1条回答
网友
1楼 · 发布于 2024-05-20 16:05:42

我可以通过使用driver.find_element_by_xpath("/html/body/pre")获得pre标记中的所有文本

代码(Chrome):

from selenium import webdriver

driver = webdriver.Chrome()

driver.get(
    "http://www.cbs.dtu.dk/cgi-bin/webface2.fcgi?jobid=5F21AC9A000078434DBE2580&wait=20")
pre_text = driver.find_element_by_xpath("/html/body/pre").text # gets the pre text


print(pre_text)

代码(Firefox):

from selenium import webdriver

driver = webdriver.Firefox()

driver.get(
    "http://www.cbs.dtu.dk/cgi-bin/webface2.fcgi?jobid=5F21AC9A000078434DBE2580&wait=20")
pre_text = driver.find_element_by_xpath("/html/body/pre").text

print(pre_text)

输出:

# NetMHCpan version 4.1b

# Tmpdir made /usr/opt/www/webface/tmp/server/netmhcpan/5F21AC9A000078434DBE2580/netMHCpangwUDuR
# Input is in FSA format

# Peptide length 9

# Make EL predictions

HLA-A01:01 : Distance to training data  0.000 (using nearest neighbor HLA-A01:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-A*01:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0046960    7.476
   2 HLA-A*01:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0045910    7.581
   3 HLA-A*01:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0017130   13.642
   4 HLA-A*01:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0268270    2.868
   5 HLA-A*01:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0008990   19.889
   6 HLA-A*01:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0054000    6.931
   7 HLA-A*01:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0013350   15.772
                                                             -

Protein Sequence. Allele HLA-A*01:01. Number of high binders 0. Number of weak binders 0. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-A01:01
                                         -

HLA-A02:01 : Distance to training data  0.000 (using nearest neighbor HLA-A02:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-A*02:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000540   49.750
   2 HLA-A*02:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0000210   63.750
   3 HLA-A*02:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000230   62.500
   4 HLA-A*02:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.2437300    0.949 <= WB
   5 HLA-A*02:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0002100   32.111
   6 HLA-A*02:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0105610    6.565
   7 HLA-A*02:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0024300   12.546
                                                             -

Protein Sequence. Allele HLA-A*02:01. Number of high binders 0. Number of weak binders 1. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-A02:01
                                         -

HLA-A03:01 : Distance to training data  0.000 (using nearest neighbor HLA-A03:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-A*03:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0001350   30.273
   2 HLA-A*03:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0003670   20.630
   3 HLA-A*03:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0006280   16.760
   4 HLA-A*03:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0238070    3.854
   5 HLA-A*03:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0003990   19.947
   6 HLA-A*03:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0002880   22.657
   7 HLA-A*03:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0001470   29.308
                                                             -

Protein Sequence. Allele HLA-A*03:01. Number of high binders 0. Number of weak binders 0. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-A03:01
                                         -

HLA-A24:02 : Distance to training data  0.000 (using nearest neighbor HLA-A24:02)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-A*24:02      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000020   80.000
   2 HLA-A*24:02      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0000480   33.750
   3 HLA-A*24:02      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000200   44.000
   4 HLA-A*24:02      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0577830    1.703 <= WB
   5 HLA-A*24:02      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0965440    1.280 <= WB
   6 HLA-A*24:02      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0032610    6.706
   7 HLA-A*24:02      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0797820    1.431 <= WB
                                                             -

Protein Sequence. Allele HLA-A*24:02. Number of high binders 0. Number of weak binders 3. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-A24:02
                                         -

HLA-A26:01 : Distance to training data  0.000 (using nearest neighbor HLA-A26:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-A*26:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0001060   35.556
   2 HLA-A*26:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0002580   25.654
   3 HLA-A*26:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0081970    5.217
   4 HLA-A*26:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0976610    1.070 <= WB
   5 HLA-A*26:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0005860   18.306
   6 HLA-A*26:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0038720    7.729
   7 HLA-A*26:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0003450   22.842
                                                             -

Protein Sequence. Allele HLA-A*26:01. Number of high binders 0. Number of weak binders 1. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-A26:01
                                         -

HLA-B07:02 : Distance to training data  0.000 (using nearest neighbor HLA-B07:02)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*07:02      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000160   68.000
   2 HLA-B*07:02      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0000600   46.750
   3 HLA-B*07:02      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000250   60.714
   4 HLA-B*07:02      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0024230   10.079
   5 HLA-B*07:02      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0094630    5.272
   6 HLA-B*07:02      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0091830    5.348
   7 HLA-B*07:02      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0002790   26.192
                                                             -

Protein Sequence. Allele HLA-B*07:02. Number of high binders 0. Number of weak binders 0. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B07:02
                                         -

HLA-B08:01 : Distance to training data  0.000 (using nearest neighbor HLA-B08:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*08:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000700   63.409
   2 HLA-B*08:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0002690   41.333
   3 HLA-B*08:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0001180   54.512
   4 HLA-B*08:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0082280    8.907
   5 HLA-B*08:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.1109260    1.478 <= WB
   6 HLA-B*08:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.2449270    0.644 <= WB
   7 HLA-B*08:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0830030    1.926 <= WB
                                                             -

Protein Sequence. Allele HLA-B*08:01. Number of high binders 0. Number of weak binders 3. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B08:01
                                         -

HLA-B27:05 : Distance to training data  0.000 (using nearest neighbor HLA-B27:05)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*27:05      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000140   65.000
   2 HLA-B*27:05      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0001850   27.278
   3 HLA-B*27:05      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000510   44.000
   4 HLA-B*27:05      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0106230    5.231
   5 HLA-B*27:05      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0005460   17.557
   6 HLA-B*27:05      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0059040    6.668
   7 HLA-B*27:05      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0008280   14.816
                                                             -

Protein Sequence. Allele HLA-B*27:05. Number of high binders 0. Number of weak binders 0. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B27:05
                                         -

HLA-B39:01 : Distance to training data  0.000 (using nearest neighbor HLA-B39:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*39:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000030   80.000
   2 HLA-B*39:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0000830   37.000
   3 HLA-B*39:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000500   43.250
   4 HLA-B*39:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0078790    6.031
   5 HLA-B*39:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0138640    4.423
   6 HLA-B*39:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0922070    1.394 <= WB
   7 HLA-B*39:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0007930   16.756
                                                             -

Protein Sequence. Allele HLA-B*39:01. Number of high binders 0. Number of weak binders 1. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B39:01
                                         -

HLA-B40:01 : Distance to training data  0.000 (using nearest neighbor HLA-B40:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*40:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000010   85.000
   2 HLA-B*40:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0003270   15.064
   3 HLA-B*40:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000050   62.500
   4 HLA-B*40:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0040450    5.141
   5 HLA-B*40:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0007510   10.653
   6 HLA-B*40:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0130780    3.155
   7 HLA-B*40:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0000240   40.500
                                                             -

Protein Sequence. Allele HLA-B*40:01. Number of high binders 0. Number of weak binders 0. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B40:01
                                         -

HLA-B58:01 : Distance to training data  0.000 (using nearest neighbor HLA-B58:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*58:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000180   74.286
   2 HLA-B*58:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0010330   18.059
   3 HLA-B*58:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0002550   32.950
   4 HLA-B*58:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.3524310    0.756 <= WB
   5 HLA-B*58:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0011160   17.476
   6 HLA-B*58:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0055600    8.227
   7 HLA-B*58:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0001540   40.000
                                                             -

Protein Sequence. Allele HLA-B*58:01. Number of high binders 0. Number of weak binders 1. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B58:01
                                         -

HLA-B15:01 : Distance to training data  0.000 (using nearest neighbor HLA-B15:01)

# Rank Threshold for Strong binding peptides   0.500
# Rank Threshold for Weak binding peptides   2.000
                                                             -
 Pos         MHC        Peptide      Core Of Gp Gl Ip Il        Icore        Identity  Score_EL %Rank_EL BindLevel
                                                             -
   1 HLA-B*15:01      CIDSTFNWQ CIDSTFNWQ  0  0  0  0  0    CIDSTFNWQ        Sequence 0.0000250   62.500
   2 HLA-B*15:01      IDSTFNWQH IDSTFNWQH  0  0  0  0  0    IDSTFNWQH        Sequence 0.0002870   29.593
   3 HLA-B*15:01      DSTFNWQHR DSTFNWQHR  0  0  0  0  0    DSTFNWQHR        Sequence 0.0000110   74.000
   4 HLA-B*15:01      STFNWQHRI STFNWQHRI  0  0  0  0  0    STFNWQHRI        Sequence 0.0065120    8.706
   5 HLA-B*15:01      TFNWQHRIL TFNWQHRIL  0  0  0  0  0    TFNWQHRIL        Sequence 0.0009100   19.116
   6 HLA-B*15:01      FNWQHRILL FNWQHRILL  0  0  0  0  0    FNWQHRILL        Sequence 0.0028310   12.227
   7 HLA-B*15:01      NWQHRILLV NWQHRILLV  0  0  0  0  0    NWQHRILLV        Sequence 0.0001040   42.000
                                                             -

Protein Sequence. Allele HLA-B*15:01. Number of high binders 0. Number of weak binders 0. Number of peptides 7

Link to Allele Frequencies in Worldwide Populations HLA-B15:01
                                         -

Explain the output.  Go back.

相关问题 更多 >