python beautifulsoup href打印为#

python beautifulsoup href打印为#,python,beautifulsoup,python-requests,urllib,Python,Beautifulsoup,Python Requests,Urllib,当我尝试为一个.zip文件提取一个特定的href时,返回的结果是# 我已经把我的剧本删去了,所以只剩下棘手的部分了。当我在不使用opener.open的情况下使用测试html(目标站点的副本)运行脚本时,它工作得很好。当我在实际站点上运行它时,我只收到# 任何帮助都将不胜感激 #!usr/bin/env python3 from bs4 import BeautifulSoup import urllib.request class Opener(urllib.request.FancyUR

当我尝试为一个.zip文件提取一个特定的href时,返回的结果是#

我已经把我的剧本删去了,所以只剩下棘手的部分了。当我在不使用opener.open的情况下使用测试html(目标站点的副本)运行脚本时,它工作得很好。当我在实际站点上运行它时,我只收到#

任何帮助都将不胜感激

#!usr/bin/env python3

from bs4 import BeautifulSoup
import urllib.request

class Opener(urllib.request.FancyURLopener):
    version = "Mozilla/5.0"

opener = Opener()

test = '<a id="dlbutton" href="https://www55.zippyshare.com/d/H7prSkjz/2176/Barrier%20Line%20Riddim%20-%20%20J.%20Small%20Records.zip"><div class="download"></div></a>'

dstar = 'https://www55.zippyshare.com/v/H7prSkjz/file.html'

def grabzip(url):
    link = BeautifulSoup(opener.open(url), "html.parser")
    for ziplink in link.find_all('a', id="dlbutton"):
       print(ziplink.get('href'))

grabzip(dstar)
#!usr/bin/env蟒蛇3
从bs4导入BeautifulSoup
导入urllib.request
类开启器(urllib.request.FancyURLopener):
version=“Mozilla/5.0”
opener=opener()
测试=“”
dstar公司https://www55.zippyshare.com/v/H7prSkjz/file.html'
def grabzip(url):
link=BeautifulSoup(opener.open(url),“html.parser”)
用于链接中的拉链。查找所有('a',id=“dlbutton”):
打印(ziplink.get('href'))
grabzip(dstar)
您可以使用Selenium/动态浏览站点并获取href:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()  
chrome_options.add_argument("--headless")  
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www55.zippyshare.com/v/H7prSkjz/file.html")

print(driver.find_element_by_id("dlbutton").get_attribute("href"))
输出
https://www55.zippyshare.com/d/H7prSkjz/16761/Barrier%20Line%20Riddim%20-%20%20J.%20Small%20Records.zip

看起来链接是通过Javascript注入的。您是如何制作本地测试副本的?手工制作,使用luakit inspect元件。