亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在python中的HTML中打印出函數變量?

如何在python中的HTML中打印出函數變量?

素胚勾勒不出你 2021-09-28 16:15:25
我是一個自學者和初學者,搜索了很多,但可能缺乏搜索。我正在從兩個網站上抓取一些值,我想將它們與 HTML 輸出進行比較。每個網頁,我都將兩個類組合在一起并進入一個列表。但是當使用 HTML 進行輸出時,我不希望打印所有列表。所以我做了功能來選擇任何要打印的關鍵字。當我想打印出該函數時,它在 HTML 輸出中顯示為“無”,但在控制臺上卻變成了我想要的。那么如何顯示那個特殊列表呢?操作系統= Windows ,Python3。from bs4 import BeautifulSoupimport requestsimport datetimeimport osimport webbrowsercarf_meySayf = requests.get('https://www.carrefoursa.com/tr/tr/meyve/c/1015?show=All').textcarf_soup = BeautifulSoup(carf_meySayf, 'lxml')#spanscarf_name_span = carf_soup.find_all('span', {'class' : 'item-name'})carf_price_span = carf_soup.find_all('span', {'class' : 'item-price'})#spans to listcarf_name_list = [span.get_text() for span in carf_name_span]carf_price_list = [span.get_text() for span in carf_price_span]#combine listscarf_mey_all = [carf_name_list +' = ' + carf_price_list for carf_name_list, carf_price_list in zip(carf_name_list, carf_price_list)]#Function to choose and print special productdef test(namelist,product):    for i in namelist:        if product in i:            print(i)a = test(carf_mey_all,'Muz')# Datedate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")# HTML parthtml_str = """<html>    <title>Listeler</title>        <h2>Tarih: %s</h2>        <h3>Product & Shop List</h3>            <table style="width:100%%">                <tr>                    <th>Carrefour</th>                </tr>                <tr>                 %s                </tr></html>""" whole = html_str %(date,a)Html_file= open("Meyve.html","w")Html_file.write(whole)Html_file.close()
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 290 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號