- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章使用python爬虫获取黄金价格的核心代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
继续练手,根据之前获取汽油价格的方式获取了金价,暂时没钱投资,看看而已 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
获取每天黄金价格
@author: yufei
@site: http://www.antuan.com
2017-05-11
"""
import
re
import
urllib2,urllib
import
random
import
threading
import
time
import
sqlite3
import
sys
from
__builtin__
import
exit
#Some User Agents
hds
=
[{
'User-Agent'
:
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
},\
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'
},\
{
'User-Agent'
:
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'
},\
{
'User-Agent'
:
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0'
},\
{
'User-Agent'
:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36'
},\
{
'User-Agent'
:
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50'
},\
{
'User-Agent'
:
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50'
},\
{
'User-Agent'
:
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0'
},\
{
'User-Agent'
:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'
},\
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'
},\
{
'User-Agent'
:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'
},\
{
'User-Agent'
:
'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11'
},\
{
'User-Agent'
:
'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11'
}]
'''
create table GoldPricelist(
[id] integer PRIMARY KEY autoincrement,
[name] varchar default 0,
[price] varchar default 0,
[time] datetime default (datetime('now', 'localtime'))
);
INSERT INTO OilPrice(id,name,price,time) VALUES(NULL,sss, 300, 20180404);
'''
def
sqliteinto(Pricelist):
con
=
sqlite3.connect(
'F:\ID\python\sqlite3\Gold.db'
)
cur
=
con.cursor()
print
Pricelist
sql
=
'''INSERT INTO GoldPrices (id,name,price,time) VALUES(NULL,?,?,?)'''
cur.execute(sql,Pricelist)
con.commit()
cur.close()
con.close()
def
getPrice():
url
=
'http://www.dyhjw.com/matter_gold/'
req
=
urllib2.Request(url
=
url,headers
=
hds[random.randint(
0
,
len
(hds)
-
1
)])
res
=
urllib2.urlopen(req)
res
=
res.read()
#获取的块
re_set
=
re.
compile
(r
'<dl class="main_bname">(.*?)</div>'
,re.S)
re_get
=
re.findall(re_set,res)
#获取价格详情
p
=
re.
compile
(
'target="_blank">(.*?)<span class="zd">-</span>\n '
,re.S)
Pricelist
=
re.findall(p,re_get[
0
])
for
i
in
range
(
0
,
len
(Pricelist)):
p
=
re.
compile
(
'(.*?)</a>\n <span class="jg">(.*)</span>'
,re.S)
Price
=
re.findall(p,Pricelist[i])
gname
=
Price[
0
][
0
]
gprice
=
Price[
0
][
1
]
timep
=
re.
compile
(r
"(\d+)-(\d+)-.*"
)
nowtime
=
time.strftime(
'%Y-%m-%d'
,time.localtime(time.time()))
datas
=
[]
datas.append(gname.decode(
'utf8'
))
datas.append(gprice)
datas.append(nowtime)
datas
=
tuple
(datas)
sqliteinto(datas)
if
__name__
=
=
"__main__"
:
getPrice()
|
最近的数据 。
总结 。
以上所述是小编给大家介绍的使用python爬虫获取黄金价格的核心代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我网站的支持! 。
原文链接:https://blog.csdn.net/yufei6808/article/details/80663304 。
最后此篇关于使用python爬虫获取黄金价格的核心代码的文章就讲到这里了,如果你想了解更多关于使用python爬虫获取黄金价格的核心代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我需要一些帮助。 我希望“总计”由“数量*价格=总计”计算(到目前为止没问题)。问题是我还需要通过“总/价格=数量”来计算“数量”,即如果一个字段发生更改,另一个字段也会自动更改。 我做了一个非常简单
我试图将每件商品的数量和价格相乘来计算总数,但我的警报中出现错误。 $.each(data.items, function(index, d){ var calcultest = d.pric
我想获得格式化的价格但没有货币符号,我只想使用 magento 的标准功能! $product->getFinalPrice(); => 19.9900 Mage::helper('core')->f
我正在尝试获取特定月份和年份中所有父类别的总价格。父类别是 parent_id == 0 的任何类别。我的查询如下所示: SELECT ROUND(SUM(od.total_price)) a
请帮我摆脱我的头痛..提前我为我的糟糕语言道歉,无论是英语还是mysql。希望有人能理解这个问题..:) 我有一个数据库,任何人都可以记录各个商店中各种产品的价格。以下查询是一个半理论示例,可能根本不
下面是我需要在数据库中设计的示例: 会有一个价格选项,如果有的话,会有一个特价选项,然后我想知道如果我希望其中一个选项是“免费”的,我该怎么做。 另请参阅根据所在国家/地区会有不同的货币。这是我的想法
商品价格格式 999,99 999 - 1 ..4 digits , - comma sign marks decimal point 99 - 2 digits after price Postg
我有这个表 stk +---------+--------------+ | Field | Type | +---------+--------------+ | id
是否有一个简单的格式化程序可以将我的字符串格式化为价格? 所以我的字符串是:300000 我想用空格来“300 000” or 1000000 "1 000 000" 张国荣 最佳答案 这样做: St
我想知道是否可以使用不依赖于 Excel 应用程序本地化(欧盟/美国)的 Excel 公式来自定义数字格式? 例如,我的值为 1291660。 然后使用公式=TEXT(A1;"# ##0,00") .
这是我的代码,对于价格 slider : $("#price-slider").ionRangeSlider({ min: 130, max: 575, onChange :
用户可以使用价格创建一个新实体。价格可以使用不同的货币(EUR,USD ...),因此我们可以乘以(price * convert_rate)得到实际价格。 我想做的是根据价格过滤记录,具体取决于前端
我正在尝试隐藏小数位在类型输入字段上,例如 数字从0.00开始 因此,输入字段中的第一个位置将为 0.00 我输入的1比它应该变成0.01 我输入的2比它应该变成0.12 比 0 所以它应该变成 1.
$res=mysql_query($qry); while($row= mysql_fetch_array($res)) { echo "".$row['Food_Name']." ".$row['P
我们正在为我们的新项目寻找信用卡网关。那里一片困惑,所有人都想把你切成碎片。每次我与他们交谈时,他们都有不同的费率,每次更新报价时,他们都会更改一些价格。 我们正在使用 .net、C#、asp.net
我已经创建了一个 jQuery 价格 slider ,但我不确定如何让过滤区域以实际价格范围开始?目前它有“$[object Object] - $[object Object]”,而我希望它有“$2
我已经创建了 jquery 价格 slider ,但我不确定如何过滤我的结果,以便在滑动时您只能看到具有该值范围内的产品。 HTML: Price range:
我有一个页面,其中有一个表格,我们可以在其中选择一个产品,输入它的数量和价格,然后应在最后一列中计算金额,并应添加新行以输入更多产品,直到我们完成为止。
我创建了电子商务网站,即将提供午餐和晚餐服务。我在这里提出问题/问题是因为我知道这里有很多可以帮助我的传奇人物。我在网站上添加了套餐/计划部分。 1. Weekly 2. Monthly 以下是订
我的网站需要一个简单的 jQuery 价格 slider 。从 0 英镑到 1000 英镑不等。 假设浏览器将 slider 设置为 100 英镑(例如),然后我需要一个立即购买按钮,该按钮将 sli
我是一名优秀的程序员,十分优秀!