2017-05-26 70 views
0

點擊頁面上的我有這樣的HTML代碼:驗證碼在python

<input id="luk" type="button" class="play-bt" value="Click Here To Generate Link"> 

點擊後,我得到這個:

<iframe src="LINK_WEB" scrolling="no" frameborder="0" width="100%" height="100%" allowfullscreen="true"> 

我想 「LINK_WEB」 在一個變量。我如何在Python中做到這一點? (如果可能的話沒有硒)

我有蟒蛇這段代碼,只爲點擊按鈕(硒):

try: 
    boton = driver.find_element_by_id("luk") 
    boton.click() 
except: 
    print "Element is not present" 

但我不知道下一步該怎麼做,並使用硒不爲我的目的一個好方法,幫助我! 謝謝

回答

0

您可以使用BeautifulSoup來實現此目的。

from bs4 import BeautifulSoup 

s = '''<iframe src="LINK_WEB" scrolling="no" frameborder="0" width="100%" height="100%" allowfullscreen="true">''' 

soup = BeautifulSoup(s, 'lxml') 

iframe_tags = soup.find_all('iframe') 

for iframe in iframe_tags: 
    print(iframe.src) 

詩:如果您使用Selenium通過網站瀏覽,你可以通過輸入driver.page_source獲得頁面的源代碼。這樣你就可以改變s變量:如果你不使用Selenium

s = driver.page_source 

,您可以使用requests庫,以獲得頁面的源代碼。

+0

但是,當我點擊在唯一出現的「<輸入ID =」陸先生「類型=‘按鈕’類=‘玩-BT’VALUE =‘單擊此處生成鏈接’>」,我如何點擊這個?點擊之前的網址與之後的網址相同。 則該過程,下載(網址),點擊「捕捉新的HTML以‘