全部-我目前正在使用BS4解析网页。 BS4返回此块,该块用JS编码为字符串,无法识别我要提取的网址。
我相信我要在BS4中提取的部分在这里:
var vd1="\x3c\x73\x6f\x75\x72\x63\x65\x20\x73\x72\x63\x3d\x27";
var vd2="\x27\x20\x74\x79\x70\x65\x3d\x27\x76\x69\x64\x65\x6f\x2f\x6d\x70\x34\x27\x3e";
var luu=pkl("uggc://navzrurnira.rh/tvs.cuc?vcqrgrpgrq");
var soienfu="\x61\x78\x66\x52\x33\x64\x54\x46\x33\x72\x6b\x36\x36\x2f\x67\x4f\x65\x46\x4d\x6b\x49\x2f\x67\x6a\x77\x42\x67\x45\x66\x61\x62\x78\x33\x58\x66\x6c\x43\x44\x78\x70\x6c\x2b\x7a\x76\x38\x6b\x6c\x6a\x6b\x53\x41\x63\x4f\x34\x4a\x77\x47\x47\x78\x35\x2f\x7c\x71\x6e\x47\x49\x55\x4d\x6a\x34\x54\x48\x69\x34\x41\x45\x75\x4c\x78\x35\x58\x46\x4a\x37\x62\x65\x42\x52\x61\x37\x36\x53\x34\x6e\x46\x6f\x75\x49\x47\x55\x42\x7a\x57\x4e\x44\x61\x4a\x6a\x45\x55\x59\x56\x47\x54\x30\x3d"; soienfu=soienfu.replace(/\|/g,"1"); soienfu=vkl(soienfu); soienfu=dfgsr(soienfu);
var iusfdb="\x61\x78\x66\x52\x33\x64\x54\x46\x33\x72\x6b\x35\x36\x2b\x4d\x4f\x64\x46\x6b\x6b\x49\x2f\x67\x6a\x77\x42\x67\x45\x66\x61\x62\x78\x33\x58\x66\x6c\x43\x44\x78\x70\x6c\x2b\x7a\x76\x38\x6b\x6c\x6a\x6b\x53\x41\x63\x4f\x34\x4a\x77\x47\x47\x78\x35\x2f\x7c\x71\x6e\x47\x49\x55\x4d\x6a\x34\x54\x48\x69\x34\x41\x45\x75\x4c\x78\x35\x58\x46\x4a\x37\x62\x65\x42\x52\x61\x37\x36\x53\x34\x6e\x46\x6f\x75\x49\x47\x55\x42\x7a\x57\x4e\x44\x61\x4a\x6a\x45\x55\x59\x56\x47\x54\x30\x3d"; iusfdb=iusfdb.replace(/\|/g,"1"); iusfdb=vkl(iusfdb); iusfdb=dfgsr(iusfdb);
var ufbjhse="\x61\x78\x66\x52\x33\x64\x54\x46\x33\x72\x6b\x34\x36\x66\x45\x65\x50\x7c\x6c\x6b\x4b\x2f\x73\x76\x78\x52\x67\x4e\x62\x71\x4c\x70\x6c\x6e\x79\x2b\x51\x6e\x35\x30\x6b\x4c\x57\x7a\x74\x6b\x67\x2f\x6b\x48\x77\x32\x64\x61\x7c\x6a\x43\x45\x46\x55\x77\x57\x65\x71\x58\x4d\x51\x51\x6c\x59\x44\x64\x6b\x35\x77\x64\x76\x62\x46\x38\x56\x46\x70\x37\x59\x4f\x6b\x36\x44\x49\x54\x2f\x34\x58\x4d\x2b\x37\x70\x2b\x66\x57\x57\x7a\x43\x54\x75\x6f\x68\x45\x55\x52\x58"; ufbjhse=ufbjhse.replace(/\|/g,"1"); ufbjhse=vkl(ufbjhse); ufbjhse=dfgsr(ufbjhse);
document.write("<video "+" class='vid' id='videodiv' width='100%' autoplay='autoplay' preload='none'>"+ vd1 +soienfu+ vd2 + vd1+iusfdb+ vd2 + vd1+ufbjhse+ vd2 +"Your browser does not support the video tag.</video> ");
}
但是,如果我在网站的HTML中看到了此消息,则会得到:
您的浏览器不支持视频标签。
理想情况下,我想将视频地址拉出html块。
http://s4tyh.animeheaven.eu/720kl/msl/Fairy_Tail--55--1449108237__2b0af6.mp4?ww5w75
我用来到达那里的代码看起来像这样。
import requests,bs4,re,sys,os
url="http://animeheaven.eu/watch.php?a=Fairy%20Tail&e=55"
mainsite="http://animeheaven.eu/"
r2=requests.get(url)
r2.raise_for_status()
soup2=bs4.BeautifulSoup(r2.text,"html.parser")
dlink=soup2.select("script")
现在,从理论上讲,我现在想在此处为URL解析dlink,但是JS似乎引起了问题。我对JS和Web抓取的新知识不太熟悉,所以这就是我要追赶的地方。
# would extract standard url
mylink=re.compile(r"href='(.*)'")
downlink=mylink.search(str(dlink[3]))[1]
答案 0 :(得分:0)
此网页是用javascript呈现的网页,脚本中包含的内容称为“最小化内容”,人类无法理解(而且很漂亮)。
Selenium是一种执行用于呈现网站的javascript的方式,然后我们可以在该网站中处理内容。
我将逐步介绍获取和使用硒的步骤:
1。用pip install selenium
2。安装一个driver(我用过chrome driver)
3。使用选定的浏览器查看带有“检查元素”的视频元素(单击鼠标右键,您会看到它),并寻找可以识别视频源代码的内容,在这种情况下,视频具有id
,其值为videodiv
。如果我们检查此html,它看起来像:
<video id="videodiv" width="100%" height="100%" style="display: block; cursor: none;" autoplay="autoplay" preload="none">
<source src="http://s5vkxea.animeheaven.eu/720kl/msl/Fairy_Tail--55--1449108237__2b0af6.mp4?ww5w130" type="video/mp4">
<source src="http://s4tyh.animeheaven.eu/720kl/msl/Fairy_Tail--55--1449108237__2b0af6.mp4?ww5w130" type="video/mp4">
<source src="http://s3sd.animeheaven.eu/720kl/msl/Fairy_Tail--55--1449108237__2b0af6.mp4?ww5w130" type="video/mp4">Your browser does not support the video tag.</video>
4。使用上面刚刚找到的id和标签,我们现在可以编写一些python来检索它:
from selenium import webdriver
browser = webdriver.Chrome(executable_path="C:\Users\yourname\Desktop\chromedriver.exe")
url="http://animeheaven.eu/watch.php?a=Fairy%20Tail&e=55"
browser.get(url)
viddiv = browser.find_element_by_id('videodiv')
source = viddiv.find_element_by_tag_name('source')
source.get_attribute('src')
输出:
'http://s5vkxea.animeheaven.eu/720kl/msl/Fairy_Tail--55--1449108237__2b0af6.mp4?ww5w130'