蟒蛇网页抓取选择下拉菜单



我正在尝试抓取此网页:http://animeheaven.eu/watch.php?a=My%20Hero%20Academia%203&e=2并下载视频。如您所见,它加载了720p视频。我可以从这里下载视频。但是我不知道如何从下拉菜单中获取其他视频版本,即480p版本。如何选择 480p 链接?

如果您使用参数 "rs" = "1" 发出 POST 请求,您将获得所需的数据。

from bs4 import BeautifulSoup
import requests
link = "http://animeheaven.eu/watch.php?a=My%20Hero%20Academia%203&e=2"
html= requests.post(link, data = {'rs': '1'})
soup= BeautifulSoup(html.content,"lxml")
scripts= soup.findAll("script")
sc=scripts[4]
print (sc)
...

输出:

...
document.write("<a  class='an' href='"+ pli +"'><div class='dl2'>Download  159 MB</div></a>");
...

不:

...
document.write("<a  class='an' href='"+ pli +"'><div class='dl2'>Download  255 MB</div></a>");
...

更新以回应评论:

...
select = soup.find("select", {'name': 'rs'})
for option in select.find_all('option'):
    print ("{} = {}".format(option.text, option['value']))

输出

720p = 0
480p = 1

最新更新