2017-05-26 67 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以‘