【爬虫实战】——利用bs4和sqlalchemy操作mysql数据库,实现网站多行数据表格爬取数据

cnblogs 2024-08-29 08:09:01 阅读 52

前言

此篇接上一篇的内容,在其基础上爬取网站的多行表格数据,以及把数据写入到mysql数据库中

目录

  • 一、定位表格查找元素
  • 二、提取数据
  • 三、写入mysql数据库
  • 四、附录

一、定位表格查找元素

首先打开网站,如图需要爬取多行数据的表格,利用查找元素定位,看图中分析得知我要爬取的是tr下的td数据,所以先查找到tr行

<code> def script(self):

# 先定位查找到tr行元素

trs = self.soup().select('.content>table>tbody>tr')

print(trs)

【查看运行结果:点击查看代码】

[<tr><td align="center" colspan="8">2024年8月27日天津热轧板卷价格今日报价表(新)_最新价格行情走势</td></tr>, <tr><td>品名</td><td>规格(mm)</td><td>材质</td><td>产地</td><td>价格(元/吨)</td><td>涨跌</td><td>备注</td></tr>, <tr><td>热轧板卷</td><td>2.0*1250*C</td><td>Q235B</td><td>河钢承钢</td><td>3320</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>2.5*1250*C</td><td>Q235B</td><td>河钢唐钢</td><td>3270</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>2.5*1250*C</td><td>Q235B</td><td>通钢</td><td>3260</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>2.5*1250*C</td><td>Q235B</td><td>河钢承钢</td><td>3270</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>2.75*1250*C</td><td>Q235B</td><td>河钢承钢</td><td>3210</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>2.75*1500*C</td><td>Q235B</td><td>包钢</td><td>3210</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>2.75*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3210</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>2.75*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3210</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>2.75*1500*C</td><td>Q235B</td><td>通钢</td><td>3200</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.0*1500*C</td><td>Q235B</td><td>包钢</td><td>3190</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.0*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3190</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.0*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3190</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>3.0*1500*C</td><td>Q235B</td><td>通钢</td><td>3180</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.5*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.5*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.5*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>3.5*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.5*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3170</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.75*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>3.75*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.75*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>3.75*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>3.75*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.5*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.5*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.5*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>4.5*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.5*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.75*1500*C</td><td>Q235B</td><td>首钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.75*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.75*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.75*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>4.75*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>4.75*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>5.5*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.5*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.5*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>5.5*1500*C</td><td>Q235B</td><td>首钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.5*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.5*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>5.75*1500*C</td><td>Q235B</td><td>首钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>7.5-11.75*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>7.5-11.75*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>7.5-11.75*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td> </td></tr>, <tr><td>热轧板卷</td><td>7.5-11.75*1500*C</td><td>Q235B</td><td>首钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>7.5-11.75*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>7.5-11.75*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1500*C</td><td>Q235B</td><td>首钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1500*C</td><td>Q235B</td><td>包钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1500*C</td><td>Q235B</td><td>河钢承钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1500*C</td><td>Q235B</td><td>河钢唐钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1500*C</td><td>Q235B</td><td>首钢</td><td>3160</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1500*C</td><td>Q235B</td><td>本钢</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1500*C</td><td>Q235B</td><td>沧州中铁</td><td>3150</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*1800*C</td><td>Q235B</td><td>包钢</td><td>3290</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*1800*C</td><td>Q235B</td><td>包钢</td><td>3290</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*1800*C</td><td>Q235B</td><td>包钢</td><td>3300</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>5.75*2000*C</td><td>Q235B</td><td>包钢</td><td>3310</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>7.75*2000*C</td><td>Q235B</td><td>包钢</td><td>3310</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.5*2000*C</td><td>Q235B</td><td>包钢</td><td>3310</td><td>涨10</td><td></td></tr>, <tr><td>热轧板卷</td><td>13.75*2000*C</td><td>Q235B</td><td>包钢</td><td>3310</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>4.75*1500*C</td><td>Q355B</td><td>包钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>4.75*1500*C</td><td>Q355B</td><td>河钢承钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>4.75*1500*C</td><td>Q355B</td><td>河钢唐钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>4.75*1500*C</td><td>Q355B</td><td>通钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>4.75*1500*C</td><td>Q355B</td><td>本钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.5*1500*C</td><td>Q355B</td><td>包钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.5*1500*C</td><td>Q355B</td><td>河钢承钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.5*1500*C</td><td>Q355B</td><td>河钢唐钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.5*1500*C</td><td>Q355B</td><td>通钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.5*1500*C</td><td>Q355B</td><td>本钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.75*1500*C</td><td>Q355B</td><td>包钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.75*1500*C</td><td>Q355B</td><td>河钢承钢</td><td>3340</td><td>涨10</td><td> </td></tr>, <tr><td>低合金板卷</td><td>5.75*1500*C</td><td>Q355B</td><td>河钢唐钢</td><td>3340</td><td>涨10</td><td> </td></tr>, <tr><td>低合金板卷</td><td>5.75*1500*C</td><td>Q355B</td><td>通钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>5.75*1500*C</td><td>Q355B</td><td>本钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*1500*C</td><td>Q355B</td><td>包钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*1500*C</td><td>Q355B</td><td>河钢承钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*1500*C</td><td>Q355B</td><td>河钢唐钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*1500*C</td><td>Q355B</td><td>通钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*1500*C</td><td>Q355B</td><td>本钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>11.75*1500*C</td><td>Q355B</td><td>包钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>11.75*1500*C</td><td>Q355B</td><td>河钢承钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>11.75*1500*C</td><td>Q355B</td><td>河钢唐钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>11.75*1500*C</td><td>Q355B</td><td>通钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>11.75*1500*C</td><td>Q355B</td><td>本钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*1500*C</td><td>Q355B</td><td>包钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*1500*C</td><td>Q355B</td><td>河钢承钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*1500*C</td><td>Q355B</td><td>河钢唐钢</td><td>3340</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*1500*C</td><td>Q355B</td><td>通钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*1500*C</td><td>Q355B</td><td>本钢</td><td>3330</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>7.75*1800*C</td><td>Q355B</td><td>包钢</td><td>3520</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*1800*C</td><td>Q355B</td><td>包钢</td><td>3520</td><td>涨10</td><td> </td></tr>, <tr><td>低合金板卷</td><td>13.5*1800*C</td><td>Q355B</td><td>包钢</td><td>3520</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*1800*C</td><td>Q355B</td><td>包钢</td><td>3520</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>7.75*2000*C</td><td>Q355B</td><td>包钢</td><td>3530</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>9.75*2000*C</td><td>Q355B</td><td>包钢</td><td>3530</td><td>涨10</td><td> </td></tr>, <tr><td>低合金板卷</td><td>13.5*2000*C</td><td>Q355B</td><td>包钢</td><td>3530</td><td>涨10</td><td></td></tr>, <tr><td>低合金板卷</td><td>13.75*2000*C</td><td>Q355B</td><td>包钢</td><td>3530</td><td>涨10</td><td></td></tr>]code>

二、提取数据

我们可以看到爬取出每行的tr和tr下面的td数据,接下来利用for循环把tr每行的文字提取出来,但是前两行是我不需要的,我只要第三行之后的数据

代码如下:

<code> def __init__(self):

# self.url = "https://www.cnblogs.com/Owen-ET/p/14523426.html"

self.url = "http://www.gtgqw.com/j/showhz2136672.html"

# url = "http://www.example.com"

self.dic = {

"报价": []

}

def script(self):

trs = self.soup().select('.content>table>tbody>tr')

print(trs)

print("=========================此处代码↓========================================")

for tr in trs:

if (tr != trs[0])&(tr != trs[1]):

movie = {}

infos = list(tr.stripped_strings)

print(infos) # 输出结果①:把td里面的值遍历出来组成数组

movie['pin_name'] = infos[0]

movie['guige'] = infos[1]

movie['caizhi'] = infos[2]

movie['chandi'] = infos[3]

movie['jiage'] = infos[4]

movie['zhangdie'] = infos[5]

#

self.dic["报价"].append(movie)

print("========================此处代码↑=========================================")

return self.dic # 输出结果②:把每行td数组里的元素赋上键名,组成键值对

【输出结果①:点击查看代码】

['热轧板卷', '2.0*1250*C', 'Q235B', '河钢承钢', '3320', '涨10']

['热轧板卷', '2.5*1250*C', 'Q235B', '河钢唐钢', '3270', '涨10']

['热轧板卷', '2.5*1250*C', 'Q235B', '通钢', '3260', '涨10']

['热轧板卷', '2.5*1250*C', 'Q235B', '河钢承钢', '3270', '涨10']

['热轧板卷', '2.75*1250*C', 'Q235B', '河钢承钢', '3210', '涨10']

['热轧板卷', '2.75*1500*C', 'Q235B', '包钢', '3210', '涨10']

['热轧板卷', '2.75*1500*C', 'Q235B', '河钢承钢', '3210', '涨10']

['热轧板卷', '2.75*1500*C', 'Q235B', '河钢唐钢', '3210', '涨10']

['热轧板卷', '2.75*1500*C', 'Q235B', '通钢', '3200', '涨10']

['热轧板卷', '3.0*1500*C', 'Q235B', '包钢', '3190', '涨10']

['热轧板卷', '3.0*1500*C', 'Q235B', '河钢承钢', '3190', '涨10']

['热轧板卷', '3.0*1500*C', 'Q235B', '河钢唐钢', '3190', '涨10']

['热轧板卷', '3.0*1500*C', 'Q235B', '通钢', '3180', '涨10']

['热轧板卷', '3.5*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '3.5*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '3.5*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '3.5*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '3.5*1500*C', 'Q235B', '沧州中铁', '3170', '涨10']

['热轧板卷', '3.75*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '3.75*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '3.75*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '3.75*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '3.75*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '4.5*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '4.5*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '4.5*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '4.5*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '4.5*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '4.75*1500*C', 'Q235B', '首钢', '3160', '涨10']

['热轧板卷', '4.75*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '4.75*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '4.75*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '4.75*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '4.75*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '5.5*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '5.5*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '5.5*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '5.5*1500*C', 'Q235B', '首钢', '3160', '涨10']

['热轧板卷', '5.5*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '5.5*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '5.75*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '5.75*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '5.75*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '5.75*1500*C', 'Q235B', '首钢', '3160', '涨10']

['热轧板卷', '5.75*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '5.75*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '7.5-11.75*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '7.5-11.75*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '7.5-11.75*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '7.5-11.75*1500*C', 'Q235B', '首钢', '3160', '涨10']

['热轧板卷', '7.5-11.75*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '7.5-11.75*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '13.5*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '13.5*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '13.5*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '13.5*1500*C', 'Q235B', '首钢', '3160', '涨10']

['热轧板卷', '13.5*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '13.5*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '13.75*1500*C', 'Q235B', '包钢', '3160', '涨10']

['热轧板卷', '13.75*1500*C', 'Q235B', '河钢承钢', '3160', '涨10']

['热轧板卷', '13.75*1500*C', 'Q235B', '河钢唐钢', '3160', '涨10']

['热轧板卷', '13.75*1500*C', 'Q235B', '首钢', '3160', '涨10']

['热轧板卷', '13.75*1500*C', 'Q235B', '本钢', '3150', '涨10']

['热轧板卷', '13.75*1500*C', 'Q235B', '沧州中铁', '3150', '涨10']

['热轧板卷', '5.75*1800*C', 'Q235B', '包钢', '3290', '涨10']

['热轧板卷', '13.5*1800*C', 'Q235B', '包钢', '3290', '涨10']

['热轧板卷', '13.75*1800*C', 'Q235B', '包钢', '3300', '涨10']

['热轧板卷', '5.75*2000*C', 'Q235B', '包钢', '3310', '涨10']

['热轧板卷', '7.75*2000*C', 'Q235B', '包钢', '3310', '涨10']

['热轧板卷', '13.5*2000*C', 'Q235B', '包钢', '3310', '涨10']

['热轧板卷', '13.75*2000*C', 'Q235B', '包钢', '3310', '涨10']

['低合金板卷', '4.75*1500*C', 'Q355B', '包钢', '3340', '涨10']

['低合金板卷', '4.75*1500*C', 'Q355B', '河钢承钢', '3340', '涨10']

['低合金板卷', '4.75*1500*C', 'Q355B', '河钢唐钢', '3340', '涨10']

['低合金板卷', '4.75*1500*C', 'Q355B', '通钢', '3330', '涨10']

['低合金板卷', '4.75*1500*C', 'Q355B', '本钢', '3330', '涨10']

['低合金板卷', '5.5*1500*C', 'Q355B', '包钢', '3340', '涨10']

['低合金板卷', '5.5*1500*C', 'Q355B', '河钢承钢', '3340', '涨10']

['低合金板卷', '5.5*1500*C', 'Q355B', '河钢唐钢', '3340', '涨10']

['低合金板卷', '5.5*1500*C', 'Q355B', '通钢', '3330', '涨10']

['低合金板卷', '5.5*1500*C', 'Q355B', '本钢', '3330', '涨10']

['低合金板卷', '5.75*1500*C', 'Q355B', '包钢', '3340', '涨10']

['低合金板卷', '5.75*1500*C', 'Q355B', '河钢承钢', '3340', '涨10']

['低合金板卷', '5.75*1500*C', 'Q355B', '河钢唐钢', '3340', '涨10']

['低合金板卷', '5.75*1500*C', 'Q355B', '通钢', '3330', '涨10']

['低合金板卷', '5.75*1500*C', 'Q355B', '本钢', '3330', '涨10']

['低合金板卷', '9.75*1500*C', 'Q355B', '包钢', '3340', '涨10']

['低合金板卷', '9.75*1500*C', 'Q355B', '河钢承钢', '3340', '涨10']

['低合金板卷', '9.75*1500*C', 'Q355B', '河钢唐钢', '3340', '涨10']

['低合金板卷', '9.75*1500*C', 'Q355B', '通钢', '3330', '涨10']

['低合金板卷', '9.75*1500*C', 'Q355B', '本钢', '3330', '涨10']

['低合金板卷', '11.75*1500*C', 'Q355B', '包钢', '3340', '涨10']

['低合金板卷', '11.75*1500*C', 'Q355B', '河钢承钢', '3340', '涨10']

['低合金板卷', '11.75*1500*C', 'Q355B', '河钢唐钢', '3340', '涨10']

['低合金板卷', '11.75*1500*C', 'Q355B', '通钢', '3330', '涨10']

['低合金板卷', '11.75*1500*C', 'Q355B', '本钢', '3330', '涨10']

['低合金板卷', '13.75*1500*C', 'Q355B', '包钢', '3340', '涨10']

['低合金板卷', '13.75*1500*C', 'Q355B', '河钢承钢', '3340', '涨10']

['低合金板卷', '13.75*1500*C', 'Q355B', '河钢唐钢', '3340', '涨10']

['低合金板卷', '13.75*1500*C', 'Q355B', '通钢', '3330', '涨10']

['低合金板卷', '13.75*1500*C', 'Q355B', '本钢', '3330', '涨10']

['低合金板卷', '7.75*1800*C', 'Q355B', '包钢', '3520', '涨10']

['低合金板卷', '9.75*1800*C', 'Q355B', '包钢', '3520', '涨10']

['低合金板卷', '13.5*1800*C', 'Q355B', '包钢', '3520', '涨10']

['低合金板卷', '13.75*1800*C', 'Q355B', '包钢', '3520', '涨10']

['低合金板卷', '7.75*2000*C', 'Q355B', '包钢', '3530', '涨10']

['低合金板卷', '9.75*2000*C', 'Q355B', '包钢', '3530', '涨10']

['低合金板卷', '13.5*2000*C', 'Q355B', '包钢', '3530', '涨10']

['低合金板卷', '13.75*2000*C', 'Q355B', '包钢', '3530', '涨10']

【输出结果②:点击查看代码】

{'报价': [{'pin_name': '热轧板卷', 'guige': '2.0*1250*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3320', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.5*1250*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3270', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.5*1250*C', 'caizhi': 'Q235B', 'chandi': '通钢', 'jiage': '3260', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.5*1250*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3270', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.75*1250*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3210', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.75*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3210', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3210', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3210', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '2.75*1500*C', 'caizhi': 'Q235B', 'chandi': '通钢', 'jiage': '3200', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.0*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3190', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.0*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3190', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.0*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3190', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.0*1500*C', 'caizhi': 'Q235B', 'chandi': '通钢', 'jiage': '3180', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.5*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.5*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.5*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3170', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.75*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.75*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '3.75*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.5*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.5*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.5*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q235B', 'chandi': '首钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q235B', 'chandi': '首钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q235B', 'chandi': '首钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.5-11.75*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.5-11.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.5-11.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.5-11.75*1500*C', 'caizhi': 'Q235B', 'chandi': '首钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.5-11.75*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.5-11.75*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1500*C', 'caizhi': 'Q235B', 'chandi': '首钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢承钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q235B', 'chandi': '河钢唐钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q235B', 'chandi': '首钢', 'jiage': '3160', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q235B', 'chandi': '本钢', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q235B', 'chandi': '沧州中铁', 'jiage': '3150', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*1800*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3290', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*1800*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3290', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*1800*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3300', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '5.75*2000*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3310', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '7.75*2000*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3310', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.5*2000*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3310', 'zhangdie': '涨10'}, {'pin_name': '热轧板卷', 'guige': '13.75*2000*C', 'caizhi': 'Q235B', 'chandi': '包钢', 'jiage': '3310', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢承钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢唐钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q355B', 'chandi': '通钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '4.75*1500*C', 'caizhi': 'Q355B', 'chandi': '本钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢承钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢唐钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q355B', 'chandi': '通钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.5*1500*C', 'caizhi': 'Q355B', 'chandi': '本钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢承钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢唐钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q355B', 'chandi': '通钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '5.75*1500*C', 'caizhi': 'Q355B', 'chandi': '本钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*1500*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢承钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢唐钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*1500*C', 'caizhi': 'Q355B', 'chandi': '通钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*1500*C', 'caizhi': 'Q355B', 'chandi': '本钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '11.75*1500*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '11.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢承钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '11.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢唐钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '11.75*1500*C', 'caizhi': 'Q355B', 'chandi': '通钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '11.75*1500*C', 'caizhi': 'Q355B', 'chandi': '本钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢承钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q355B', 'chandi': '河钢唐钢', 'jiage': '3340', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q355B', 'chandi': '通钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*1500*C', 'caizhi': 'Q355B', 'chandi': '本钢', 'jiage': '3330', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '7.75*1800*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3520', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*1800*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3520', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.5*1800*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3520', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*1800*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3520', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '7.75*2000*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3530', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '9.75*2000*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3530', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.5*2000*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3530', 'zhangdie': '涨10'}, {'pin_name': '低合金板卷', 'guige': '13.75*2000*C', 'caizhi': 'Q355B', 'chandi': '包钢', 'jiage': '3530', 'zhangdie': '涨10'}]}

三、写入mysql数据库

把上一步提取到的数据,利用sqlalchemy操作写入mysql数据库中,首先前提

<code> def mysql(self):

# 替换为你的数据库连接信息

DATABASE_URI = 'mysql+pymysql://root:1234567@localhost:3306/baojia'

# 创建数据库引擎

engine = create_engine(DATABASE_URI)

Session = sessionmaker(bind=engine)

session = Session()

# 定义JSON数据和表结构

json_data = self.script()['报价']

# 假设你有一个名为users的表

metadata = MetaData(bind=engine)

users_table = Table('banjuan', metadata, autoload_with=engine)

# 解析JSON数据并插入到数据库

for entry in json_data:

ins = users_table.insert().values(pin_name=entry['pin_name'],

guige=entry['guige'],

caizhi=entry['caizhi'],

chandi=entry['chandi'],

jiage=entry['jiage'],

zhangdie=entry['zhangdie'])

session.execute(ins)

# 提交更改

session.commit()

配置数据库解析:'mysql+pymysql://root:1234567@localhost:3306/baojia'

可以参考我的相关文章也有说明:Owen_ET-《【测试平台开发】——05Flask后端api开发实战(二)—— SqlAlchemy 》 *****

<code>【mysql】:使用的mysql数据库

【pymysql】:使用pymysql的引擎

【://scott】:数据库用户名

【:tiger】:数据库密码

【@localhost】:数据库地址

【/foo】:数据库的库名称

手动创建表结构:数据库名为【baojia】、表名为【banjuan】,以及各个字段值的类型、长度等

其中id设置为自动增加并且设置为键

【运行结果:查看数据库】

运行之后,mysql数据库的数据就插进来了

【完整代码】

<code>import re

import json

import requests

from bs4 import BeautifulSoup as bs

from sqlalchemy.orm import sessionmaker

from sqlalchemy import create_engine, Table, MetaData

class BS:

def __init__(self):

# self.url = "https://www.cnblogs.com/Owen-ET/p/14523426.html"

self.url = "http://www.gtgqw.com/j/showhz2136672.html"

# url = "http://www.example.com"

self.dic = {

"报价": []

}

def soup(self):

res = requests.get(self.url)

soup = bs(res.text, 'html.parser')

return soup

def script(self):

trs = self.soup().select('.content>table>tbody>tr')

print(trs)

print("=================================================================")

print("=================================================================")

for tr in trs:

if (tr != trs[0])&(tr != trs[1]):

movie = {}

infos = list(tr.stripped_strings)

print(infos)

movie['pin_name'] = infos[0]

movie['guige'] = infos[1]

movie['caizhi'] = infos[2]

movie['chandi'] = infos[3]

movie['jiage'] = infos[4]

movie['zhangdie'] = infos[5]

self.dic["报价"].append(movie)

print("=================================================================")

print("=================================================================")

return self.dic

def data(self):

# 生成json文件

with open("报价.json", 'w', encoding='utf8') as f:code>

json.dump(self.script(), f, ensure_ascii=False, indent=4)

def mysql(self):

# 替换为你的数据库连接信息

DATABASE_URI = 'mysql+pymysql://root:1234567@localhost:3306/baojia'

# 创建数据库引擎

engine = create_engine(DATABASE_URI)

Session = sessionmaker(bind=engine)

session = Session()

# 定义JSON数据和表结构

json_data = self.script()['报价']

# 假设你有一个名为users的表

metadata = MetaData(bind=engine)

users_table = Table('banjuan', metadata, autoload_with=engine)

# 解析JSON数据并插入到数据库

for entry in json_data:

ins = users_table.insert().values(pin_name=entry['pin_name'],

guige=entry['guige'],

caizhi=entry['caizhi'],

chandi=entry['chandi'],

jiage=entry['jiage'],

zhangdie=entry['zhangdie'])

session.execute(ins)

# 提交更改

session.commit()

if __name__ == '__main__':

print(BS().mysql())

四、附录

参考其他的文章:

  • 感谢作者:斑马L*-《python·数据采集·bs4(爬虫2)》 *****

  • AI智能回答:

<code>from sqlalchemy import create_engine, Table, MetaData

from sqlalchemy.orm import sessionmaker

import json

# 替换为你的数据库连接信息

DATABASE_URI = 'mysql+pymysql://user:password@localhost:3306/database'

# 创建数据库引擎

engine = create_engine(DATABASE_URI)

Session = sessionmaker(bind=engine)

session = Session()

# 定义JSON数据和表结构

json_data = '[{"id": 1, "name": "Alice", "age": 30}, {"id": 2, "name": "Bob", "age": 25}]'

# 假设你有一个名为users的表,有id, name, age字段

metadata = MetaData(bind=engine)

users_table = Table('users', metadata, autoload_with=engine)

# 解析JSON数据并插入到数据库

data = json.loads(json_data)

for entry in data:

ins = users_table.insert().values(id=entry['id'], name=entry['name'], age=entry['age'])

session.execute(ins)

# 提交更改

session.commit()



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。