from bs4 import BeautifulSoup
import requests
def getnames():
#i = 1
#for i in range(1,60):
url = requests.get('http://store.steampowered.com/search/?specials=1&page=1')#{}.format(i)
soup = BeautifulSoup(url.content,"html.parser")
games = (soup.find('div',"leftcol large").find_all('a',"search_result_row ds_collapse_flag"))
for game in games:
picture = game.find('div',"col search_capsule").img
name_of_game = game.find("span","title")
discount = game.find('div',"col search_discount responsive_secondrow")
from_price = game.find('div',"col search_price discounted responsive_secondrow").span.strike
to_price_w_from = game.find("div","col search_price discounted responsive_secondrow").span.extract()
to_price = game.find('div', "col search_price discounted responsive_secondrow")
print(name_of_game)
#i+=1
这是我用来打折的游戏名称的代码。当我运行函数时,它输出的结果是
^{pr2}$它没有什么问题。我想制作一个包含上述信息的容器并将其发送到“索引.html“位于同一文件夹中的文件。同样,制作一个容器没有什么问题,但是问题是我不能将它发送到html文件的主体部分。我试过一些东西,但没办法寄出去。如何将我拥有的内容插入html的正文部分?在
您需要一个索引文件作为模板,其中包含可替换的代码持有者—一个特殊的pythonic标记。阅读索引模板并在特定位置替换内容。更换索引.html在
下面是一个简单的例子
-索引模板-
-python代码-
^{pr2}$看看
这是要插入索引的html。在
而且
让python代码将html插入可替换代码持有者“%(ads_block)s”
当然,您可能需要对此进行调整以满足您的需求。在
您需要做的是使现有的对象的美化组对象index.html文件。使用新数据修改,然后覆盖index.html具有对象的字符串表示。Modifying the tree section of the bs4 documentation提供了有关可用于执行此操作的各种方法的信息。
一个简单的例子。
index.html
修改文件的代码
^{pr2}$修改index.html
^{pr3}$相关问题 更多 >
编程相关推荐