1 Star 0 Fork 182

GSAM / Python爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
爬取搜狗天气.py 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
耿直的小爬虫 提交于 2018-09-12 16:44 . 更新 爬取搜狗天气.py
import requests
from pyquery import PyQuery as pq
import pymongo
import time
#连接数据库
clien=pymongo.MongoClient(host='设置为自己的mongodbIP',port=27017)
#指定数据库
db=clien.tianqi
#指定集合
coll=db.tianqibianhua
def spon():
url='http://tianqi.sogou.com/?tid=101300501'
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0'
}
sponse=requests.get(url,headers=headers).text
doc=pq(sponse)
test=doc('.num').text()
shidu=doc('.hundity').text()
kongqi=doc('.liv-text').text()
shijian=doc('.row2.row2-0 .date').text()
hourweather=doc('.hours-list .list-item')
cupo='24小时温度变化情况:'+hourweather.text()
opp=str(cupo)
ttest=opp.replace('\n',' ')
#print(ttest)
tianiqi={
'时间:':time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) ,
'当前温度为':test,
'空气质量':kongqi,
'湿度':shidu
}
coll.insert(tianiqi)
while True:
spon()
time.sleep(3600)
Python
1
https://gitee.com/dushuren/python_reptilian.git
git@gitee.com:dushuren/python_reptilian.git
dushuren
python_reptilian
Python爬虫
master

搜索帮助