import requests
import json
from dbutil.pgsql import PgsqlPipeline
from datetime import date headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9', } def get_Provinces():
url = 'https://www.ftms.com.cn/website/Maintenance/getProvince'
response =requests.get(url,headers=headers,verify=False)
provinces_list= json.loads(response.text)['data']
return provinces_list def get_Citys(provinces_cid): city_url =f'https://www.ftms.com.cn/website/Maintenance/getCity?cid={provinces_cid}' res=requests.get(city_url,verify=False,headers=headers)
cities=json.loads(res.text)['data']
return cities
# print(cities) # city_list=json.loads(reponse.text)['data']
# for city_dict in city_list:
# city_cid=city_dict.get('cid')
# city_name=city_dict.get('name')
# print(city_cid,city_name)
# def get_Dealers(city_id,provinces_cid): dealers_url ='https://www.ftms.com.cn/website/Dealer/getDealer'
data={'cityName': "" ,'cityid': city_id,'dealerName': "",'provinceName': "",'provinceid': provinces_cid}
# data={"provinceid":"420000","cityid":"420700","dealerName":"","cityName":"","provinceName":""}
print(data) dealer_res=requests.post(dealers_url,headers=headers,verify=False,data=json.dumps(data))
dealers=json.loads(dealer_res.text)['data']['list']
return dealers def get_item(dealer, province_name, city_name):
item={
"dealer_name":dealer["fullname"],
"brand_id": None,
"address": dealer["address"],
"brand": "丰田",
"province": province_name,
"city": city_name,
"sale_call": dealer["phone_seal"],
"customer_service_call": dealer["phone_service"],
"update_time": date.today(),
"longitude": dealer['lng'],
"latitude": dealer['lat'],
"dealer_type": None,
"manufacturer_id": None,
"manufacturer": "丰田汽车",
"state": None,
"opening_date": None,
"close_date": None,
"dealer_id_web": None,
"controlling_shareholder": None,
"other_shareholders": None,
"status": None,
"remarks": None, } return item def get_items():
items=[]
provinces_list =get_Provinces()
for provinces_dict in provinces_list:
provinces_cid =provinces_dict.get('cid')
provinces_name=provinces_dict.get('name')
# print(provinces_cid,provinces_name) cities =get_Citys(provinces_cid)
for city in cities:
city_id =city.get('cid')
city_name=city.get('name')
# print(city_id,city_name)
dealers=get_Dealers(city_id,provinces_cid)
for dealer in dealers: print(dealer)
item=get_item(dealer,provinces_name,city_name)
items.append(item) return items def main():
print('爬虫开始.....')
items=get_items() print('等待数据存储')
pg =PgsqlPipeline()
for item in items:
pg.process_item(item)
pg.close()
print('数据存储完成!!!') if __name__ == '__main__':
main()

python 丰田经销商的更多相关文章

  1. python 日产经销商

    ''' ajaxCallSiteInfo: {1C8B2BC6-35E2-460E-A63D-3576F3039D79} ''' import requests import json from db ...

  2. 长安铃木经销商爬取(解析xml、post提交、python中使用js代码)

    1.通过火狐浏览器,查找大长安铃木官网中关于经销商的信息主要在两个网页中 http://www.changansuzuki.com/khfw/xml/pro.xml  地域信息 http://www. ...

  3. Python 爬虫实例(15) 爬取 汽车之家(汽车授权经销商)

    有人给我吹牛逼,说汽车之家反爬很厉害,我不服气,所以就爬取了一下这个网址. 本片博客的目的是重点的分析定向爬虫的过程,希望读者能学会爬虫的分析流程. 一:爬虫的目标: 打开汽车之家的链接:https: ...

  4. 利用 Python 只连接一次 MySQL

    Github 地址 项目背景 最近做个项目,需要进行试驾分析,所谓"试驾",是指顾客在 4S 店指定人员的陪同下,沿着指定的路线驾驶车辆,从而了解这款汽车的行驶性能和操控性能.通常 ...

  5. python环境jieba分词的安装

    我的python环境是Anaconda3安装的,由于项目需要用到分词,使用jieba分词库,在此总结一下安装方法. 安装说明======= 代码对 Python 2/3 均兼容 * 全自动安装:`ea ...

  6. python第三方库------jieba库(中文分词)

    jieba“结巴”中文分词:做最好的 Python 中文分词组件 github:https://github.com/fxsjy/jieba 特点支持三种分词模式: 精确模式,试图将句子最精确地切开, ...

  7. python之jieba库

    jieba “结巴”中文分词:做最好的 Python 中文分词组件 "Jieba" (Chinese for "to stutter") Chinese tex ...

  8. Python设计模式 - 基础 - 七大基本原则

    提倡使用设计模式,主要出发点就是实现代码复用,增加代码的扩展性和可维护性.如何设计出简洁.易懂.灵活.优美的代码结构的确是一门学问,透彻理解并践行如下七大原则通常都能取得基本满意的结果: - 单一职责 ...

  9. python记录_day18 反射 判断函数与方法

    一.三个内置函数 1.issubclass(a, b)  判断a类是否是b类的子类 class Foo: pass class Zi(Foo): pass class Sun(Zi): pass pr ...

随机推荐

  1. Taro -- 定义全局变量

    Taro定义全局变量 方法1:在taro中 getApp()只能取到一开始定义的值,并不能取到改变后的值 // app.js文件中 class App extends Component { cons ...

  2. FTP服务器原理及配置

    控制连接 21端口  用于发送ftp命令 数据连接 20端口  用于上传下载数据 数据连接的建立类型: 1主动模式: 服务器主动发起的数据连接 首先由客户端的21 端口建立ftp控制连接 当需要传输数 ...

  3. 【LeetCode】二分 binary_search(共58题)

    [4]Median of Two Sorted Arrays [29]Divide Two Integers [33]Search in Rotated Sorted Array [34]Find F ...

  4. 将postgresql中的数据实时同步到kafka中

    参考地址:https://blog.csdn.net/weixin_33985507/article/details/92460419 参考地址:https://mp.weixin.qq.com/s/ ...

  5. 033:DTL常用过滤器(2)

    date过滤器: date过滤器:将一个日期按照指定的格式,格式化成字符串.示例代码如下: views.py: from datetime import datetime def cur_date(r ...

  6. CSS3小笔记

    border-radius:圆角属性:border-radius:左上,右上,右下,左下.transform:rotate(角度):transparent 透明的三角形的写法设置宽和高为0,设置边框的 ...

  7. 带有lazy标记的线段树

    #include<bits/stdc++.h> using namespace std; ]; struct st{ int l,r,val,add; }tr[]; void build( ...

  8. RSS(简易信息聚合)和jieba(第三方分词组件)

    简易信息聚合(也叫聚合内容)是一种RSS基于XML标准,在互联网上被广泛采用的内容包装和投递协议.RSS(Really Simple Syndication)是一种描述和同步网站的内容格式,是使用最广 ...

  9. php linux环境安装ftp扩展

    1.进入PHP安装源码包,找到ext下的ftp,进入 cd /home/local/php-5.6.25/ext/ftp 2./usr/local/php/bin/phpize 3../configu ...

  10. macOS 10.14 Mojave Apache Setup: Multiple PHP Versions

    Part 1: macOS 10.14 Mojave Web Development Environment Developing web applications on macOS is a rea ...