python爬取企业名录
来源:互联网 发布:c语言编程1000例pdf 编辑:程序博客网 时间:2024/04/30 08:02
爬取企业名录然后存储到数据库中。
#-*- coding:utf-8 -*-import requestsimport MySQLdbimport refrom bs4 import BeautifulSoupheaders = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36"}cookies = {'ASPSESSIONIDQCSRSBRS':'FBEPJPLCHEEMEHNLHFKCBCGB', 'Hm_lvt_819e30d55b0d1cf6f2c4563aa3c36208':'1483118719', 'Hm_lpvt_819e30d55b0d1cf6f2c4563aa3c36208':'1483120442'}db = MySQLdb.connect("localhost","root",'liao1234','liao',charset="utf8")cursor = db.cursor()'''sql ="""create table company(name char(100) not null, type char(50), addr char(150), leader char(30), date char(30))"""cursor.execute(sql)'''#获取各地区链接r = requests.get("http://hangzhou.11467.com/",headers=headers,cookies=cookies)html = r.textsoup = BeautifulSoup(html)for tag in soup.find('div',class_='box sidesubcat t0').find_all('a'): print tag.attrs['href'] base_url = "http://hangzhou.11467.com"+tag.attrs['href']+'pn' for i in range(1,10): url = base_url + str(i) r1 = requests.get(url,headers=headers,cookies=cookies) html1 = r1.text soup1 = BeautifulSoup(html1) for tag1 in soup1.find('ul',id='slist').find_all('li'): ss = [] for cc in tag1.find_all('a'): print cc.string ss.append(cc.string) for aa in tag1.find_all('dd'): print aa.string ss.append(aa.string) if len(ss) == 3: ss.append("none") ss.append("none") elif len(ss) == 4: ss.append("none") else: pass print len(ss) if len(ss)==0: continue sql = "insert into company(name,type,addr,leader,date) values('%s','%s','%s','%s','%s')"%(ss[0],ss[1],ss[2],ss[3],ss[4]) cursor.execute(sql) print ss[0]db.close()
0 0
- python爬取企业名录
- python爬虫爬取机床展名录
- 广州软件企业名录
- 软件外包企业名录
- 国内机床企业名录
- 合肥软件企业名录
- 深圳市高新技术企业名录
- 张江高科技园区企业名录
- 四川金融行业企业名录
- 快嘴企业名录搜索 2007 是什么
- 龙鼎企业名录管理系统 官方
- 龙鼎企业名录查询系统 是什么
- 无锡重点服务外包企业名录
- 南京中型及以上IT企业名录
- Python爬取图片
- Python爬取图片
- python爬取图片
- Python爬取小说
- 项目提示“Your session has expired. Please log in.”
- 我的第一篇博客
- UIWebView的使用
- iOS10之后 权限设置
- hdu 2546 饭卡
- python爬取企业名录
- 【codeforces 750A】New Year and Hurry
- 【codeforces 750B】New Year and North Pole
- 求类似的进度条,实现方法或者源码
- android activity刷新
- listView加check box 问题
- 红黑树 数据结构说解
- Android蓝牙
- [200分贴]RxJava怎么实现多个线程同时执行,怎么实现retryWhen