You need to enable JavaScript to run this app. 如何用Python为Telegram机器人实现es.pdfdrive.com书籍搜索并获取URL
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python为Telegram机器人实现es.pdfdrive.com书籍搜索并获取URL

开发需求与现有进度

我是没有任何Python开发经验的编程初学者,目前正在结合Python、Telegram机器人框架和BeautifulSoup开发Telegram机器人,已经成功实现了对https://es.pdfdrive.com/的基础数据爬取。当前需要实现的功能是:支持将书名输入该网站的搜索引擎,获取每本匹配目标书籍的访问URL;此前我没有在母语渠道找到相关参考资料,也不清楚该怎么检索对应的实现方法。做这个小项目就是为了熟悉Python的实用开发能力,还望各位多多指教。

现有爬取模块代码

from bs4 import BeautifulSoup
import requests 
import pandas as pd 
url = 'https://es.pdfdrive.com/'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
#secciones
trending = soup.find_all('h2')
categories = soup.find_all('p')
trenx = list()
categ=list()
con =0

for i in trending: 
    if con < 5: 
        trenx.append(i.text)
    else: 
        break
    con += 1

for i in categories: 
    if con < 15: 
        categ.append(i.text)
    else: 
        break
    con += 1

def trend_today(update, context):
    
    update.message.reply_text('Mostrando los 5 más populares')
    for x in trenx:
        
        update.message.reply_text(x)

def categories_inlist(update, context):
    
    update.message.reply_text('Mostrando listado de  Categorias')
    for x in categ:
        
        update.message.reply_text(x)       

Telegram机器人主程序代码

from telegram.ext import Updater, CommandHandler,ConversationHandler
from scra import trend_today,categories_inlist

def start(update, context):

    update.message.reply_text('Bienvenido a Wissen')

def prueba_CommandHandler(update,context):
    update.message.reply_text('')

if __name__== '__main__':

        Updater = Updater(token='tokenid',use_context=True)
    
        dp = Updater.dispatcher 
        dp.add_handler(CommandHandler('start',start))
        dp.add_handler(ConversationHandler(
            entry_points=[
                CommandHandler('Trend',trend_today),
                CommandHandler('Categories',categories_inlist)

            ],
            states={},
            fallbacks=[]
        ))
        #handler 
        Updater.start_polling()
        Updater.idle()

内容的提问来源于stack exchange,提问作者Gabriel Medranda Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.27 12:27:06