我有以下刮板: 单击与每个链接相对应的按钮时,我想做一个导入链接的操作。
def ListarPeliculas(win, canvas, box_formulario, paginacion):
canvas.config(bg='#CCC')
#canvas.pack(side=LEFT, pady=20)
canvas.pack(side=LEFT, pady=20)
global scrollbar
scrollbar = Scrollbar(win, command=canvas.yview)
scrollbar.config(bg='#CCC')
scrollbar.pack(side=LEFT, pady=20, fill=Y)
canvas.configure(yscrollcommand=scrollbar.set)
def on_configure(event):
canvas.configure(scrollregion=canvas.bbox('all'))
canvas.bind('<Configure>', on_configure)
box_formulario.config(bg='#CCC', padx=40)
canvas.create_window((0, 0), window=box_formulario, anchor='n')
url = 'https://divxtotal7.com/peliculas/page/'+paginacion.get()
header = var.user_agent
r = requests.get(url, headers=header)
soup = html.fromstring(r.text)
links_posts = soup.xpath('//ul[@class="miniboxs miniboxs-ficha"]//div[@class="meta"]/a/@href')
titulos_posts = soup.xpath('//ul[@class="miniboxs miniboxs-ficha"]//div[@class="meta"]/a/text()')
idiomas = soup.xpath('//ul[@class="miniboxs miniboxs-ficha"]//div[@class="imagen"]//img[@class="lazy"]/@src')
row = 1
count = 0
for link_post, titulo_post, idioma in zip(links_posts, titulos_posts, idiomas):
if idioma == '/images/espanolEspañol.png' or idioma == '/images/espanolEspanol.png':
idioma = 'Español España'
elif idioma == '/images/espanolVOSE.png':
idioma = 'Subtitulado a español'
elif idioma == '/images/espanolEspanol Latino.png':
idioma = 'Español Latino'
numero = Label(box_formulario, text=str(row))
numero.config(bg='#CCC', fg='black', font=('Arial', 10), pady=5)
numero.grid(row=row, column=0, sticky='nw')
#name_peliculas = Label(box_formulario, text=titulo_post)
#name_peliculas.config(bg='#CCC', fg='black', font=('Arial', 8), pady=5)
#name_peliculas.grid(row=row, column=1, sticky='n')
peliculas_listada = Label(box_formulario, text=link_post, textvariable=link_post)
peliculas_listada.config(bg='#CCC', fg='black', font=('Arial', 10), pady=5)
peliculas_listada.grid(row=row, column=1, sticky='n', columnspan=2, padx=60)
idioma_listada = Label(box_formulario, text=idioma)
idioma_listada.config(bg='#CCC', fg='black', font=('Arial', 10), pady=5)
idioma_listada.grid(row=row, column=3, sticky='nw')
importar = Button(box_formulario, text='Importar', command=lambda: [print(link_post)])
importar.config(bg='orange', font=('Arial', 10, 'bold'))
importar.grid(row=row, column=4, sticky='e', padx=25, pady=5)
count += 1
row += 1
但是当我获得链接时,我得到的是最后一个链接,而不是每个链接对应的内容
每次单击任何按钮时,都会得到以下链接,即相同的链接,而不是与每个按钮对应的链接。
https://divxtotal7.com/descargar/43813/padre,-soldado,-hijo/
https://divxtotal7.com/descargar/43813/padre,-soldado,-hijo/
答案 0 :(得分:0)
感谢用户,解决方案是这样
procedure TForm1.Button2Click(Sender:TObject)
begin
if not assigned(_bmp) then
begin
ShowMessage('Click "Load" first');
Exit;
end;
with TPrintDialog.Create(nil) do
try
if not Execute then
Exit;
finally
Free;
end;
Printer.BeginDoc;
try
Printer.Canvas.Draw(0,0,_bmp);
finally
Printer.EndDoc;
end;
end;