我如何获取audiosrc URL?

如何解决我如何获取audiosrc URL?

我目前正在创建一个网上聊天的电报聊天机器人。我在“清理”网络抓取输出时遇到问题,尤其是当我想从 www.poetryarchive.org +文字中检索录音时。

这是我当前的代码:

# import relevant libraries for web scraping and asynchronous input/output
import asyncio
import telepot
import telepot.aio
from telepot.aio.loop import MessageLoop
from pprint import pprint
from bs4 import BeautifulSoup
import requests

# Telegram bot API token (and its configuration to aysnc version)
TOKEN = '<INSERT API TOKEN HERE>'
bot = telepot.aio.Bot(TOKEN)

# This function will be modified to accommodate our web scraper code afterwards
async def handle(msg):
    # Creating a global variable
    global chat_id
    # These variables will allow us to glance at the received messages - extract the messages' 'headline info'
    content_type,chat_type,chat_id = telepot.glance(msg)
    # Log variables
    print(content_type,chat_id)
    pprint(msg)
    username = msg['chat']['first_name']
    if content_type == 'text':
        # map the message to the '/start' function
        if msg['text'] == '/start':
            await bot.sendMessage(chat_id,"Hi! I am PoeticScraper and I am able to scrape your desired poem,its credits,the poet's information,and the poem's glossary tags. Key in '/help' for more assistance or any keywords without the '/' to get the ball rolling!")
        # map the message to the '/help' function
        elif msg['text'] == '/help':
            await bot.sendMessage(chat_id,"I am here to help! For starters,you can type any keywords in and I will retrieve the most relevant poem for you! Alternatively,if you have specific poems you want to search,you can do so too! But please note the for poem titles with multiple words,please use '-' between them!")
        elif msg['text'] == '/more':
            await bot.sendMessage(chat_id,"Can't get enough of poems? Fret not! There are so many other poetry websites for you to browse: www.poetryfoundation.org & www.poets.org")
        elif msg['text'] != '/start' or '/help':
            text = msg['text']
            # it's better to strip and lower the input in order for the subsequent function to comprehend it
            text = text.strip()
            await getInformation(text.lower())
        # if all else fails...
        else:
            await bot.sendMessage(chat_id,"404 not found!")

# the variable 'headers' is required so that the target website perceives our web-scraper as a browser
headers = {'User-Agent':
           'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/47.0.2526.106 Safari/537.36'}

# defining a function - in charge of making the HTTP request,receiving an HTML response,and retrieving the poem
async def getInformation(text):
    # specify the url - all the URLs on this website follow this convention: 'https://poetryarchive.org/poem/<insert poem name>/'
    mainpage_url = 'https://poetryarchive.org/poem/' + text
    # query the website and return the html to the variable 'page'
    page = requests.get(mainpage_url,headers = headers)
    # parse the html using BeautifulSoup and store in variable `soup`
    soup = BeautifulSoup(page.text,'html.parser')
    pprint(soup)
# this part is crucial to web-scrapping the required information from the webpage
    try:
        # poet's details
        try:
            for poet in soup.find_all('h3',{'style': 'margin-top:0px;'}):
                for poet_name in poet.find_all('a'):
                    pprint(poet_name.get_text('href'))
                    await bot.sendMessage(chat_id,poet_name)
        except:
            await bot.sendMessage(chat_id,"The poet's bio is currently unavailable.")
        # credits/copyright info about the poem
        try:
            credits = soup.find('div',{'class': 'source-box bg-grey pa-boxed small-text'}).text
            await bot.sendMessage(chat_id,credits)
        except:
            await bot.sendMessage(chat_id,"No credits found!")
        # audio version of the poem
        try:
            for audio_recording in soup.find_all('div',{'class': 'pa-player-wrap'}):
                pprint(audio_recording.get('audiosrc'))
                await bot.sendMessage(chat_id,audio_recording)
        except:
            await bot.sendMessage(chat_id,"Sorry. The audio recording is currently unavailable.")
        # textual version of the poem
        try:
            poem = soup.find('div',{'class': 'poem-content'}).text
            await bot.sendMessage(chat_id,poem)
        except:
            await bot.sendMessage(chat_id,"Sorry. The poem is currently unavailable.")
        # genre types for this poem
        try:
            for meta_tags in soup.find_all('div',{'class': 'player-metas'}):
                for tag in meta_tags.find_all('a'):
                    pprint(tag.get_text('href'))
                    await bot.sendMessage(chat_id,"These are the glossary tags associated with this poem: ")
                    await bot.sendMessage(chat_id,tag)
        except:
            await bot.sendMessage(chat_id,"Sorry. The glossary tags for this poem are currently unavailable.")
    except:
        await bot.sendMessage(chat_id,"Oh no! Something went wrong... Please enter '/help' for more information.")

# Program startup
loop = asyncio.get_event_loop()
loop.create_task(MessageLoop(bot,handle).run_forever())
print('Listening ...')

# Keep the program running
loop.run_forever()

这是我为诗“上游”获得的电报输出:

<div class="pa-player-wrap">
<div class="df-close"></div>
<div class="df-title"><h6>Upstream - Jean Binta Breeze</h6></div> <div audiosrc="https://poetryarchive.org/wp-content/uploads/poems/full/Upstream.mp3" class="pa-player for-poem-3216 paused">
<a class="pa-poem-play pa-player-control"></a>
<div class="pa-poem-progress">
<div class="timer current"></div>
<div class="pa-progress-slider">
<div class="pa-loading-bar"></div>
<div class="pa-progress-bar"></div>
</div>
<div class="timer full"></div>
</div>
<div class="pa-poem-volume" title="Volume">
<a class="pa-volume pa-player-control"></a>
<div class="pa-volume-slider-wrap">
<div class="pa-volume-slider">
<div class="pa-volume-bar">
<div class="pa-volume-handlebar" style="width: 100%;"></div>
</div>
</div>
</div>
</div>
<a class="close-df"><i class="fal fa-fw fa-times c-pink"></i></a>
<a class="close-eyes pa-player-control" title="Distraction free">
<div class="eye eye-open"></div>
<div class="eye eye-shut"></div>
</a>
<div class="pa-poem-add">
<div class="member-fav nonmember-fav" title="Become a member to add to a collection"></div> </div>
<a class="pa-poem-drag" title="Reorder collection"></a>
</div>
</div>

我该怎么做才能使我只抓取标签中的URL?我尝试了很多方法,但是没有用。

解决方法

在使用css选择器定位类为type EitherCheckboxProps = (CheckboxProps | {label: string}) & Partial<CheckboxProps> export const Checkbox: React.FunctionComponent<EitherCheckboxProps> = ({ checked,disabled,disabledTooltipLabel,id,onChange,labelOrientation = "left",label = "",className,}) => { (多值类的一部分)的元素的audiosrc属性的情况下,以下方法可能起作用

pa-player

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res