当前位置: 首页 > news >正文

网站运营技巧网站建设都分几个阶段

网站运营技巧,网站建设都分几个阶段,建筑公司网址,域名价值评估网下载chrome驱动 通过chrome浏览器的 设置-帮助-关于Google Chrome 查看你所使用的Chrome版本 驱动可以从这两个地方找: 【推荐】https://storage.googleapis.com/chrome-for-testing-publichttp://npm.taobao.org/mirrors/chromedriver import zipfile import os import r…

在这里插入图片描述

下载chrome驱动

通过chrome浏览器的 设置-帮助-关于Google Chrome 查看你所使用的Chrome版本
在这里插入图片描述

驱动可以从这两个地方找:

  • 【推荐】https://storage.googleapis.com/chrome-for-testing-public
  • http://npm.taobao.org/mirrors/chromedriver
import zipfile
import os
import requestsdef un_zip(file_name, to_dir='./'):"""unzip zip file"""zip_file = zipfile.ZipFile(file_name)if os.path.isdir(to_dir):passelse:os.mkdir(to_dir)for names in zip_file.namelist():zip_file.extract(names, to_dir)zip_file.close()def download_driver(url=None, to_dir='./', version=''):print('install chrome-driver first')if not url:url = 'http://npm.taobao.org/mirrors/chromedriver/LATEST_RELEASE'if len(version)>0:url = 'http://npm.taobao.org/mirrors/chromedriver/LATEST_RELEASE_'+versionversion = requests.get(url).content.decode('utf8')driver_file = 'http://npm.taobao.org/mirrors/chromedriver/' + version + '/chromedriver_win32.zip'else:driver_file = urlr = requests.get(driver_file)download_zip = "chromedriver_win32.zip"with open(download_zip, "wb") as code:code.write(r.content)un_zip(download_zip,  to_dir)# os.remove(download_zip)print('done')download_driver(url='https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.58/win64/chromedriver-win64.zip', to_dir='./', version='')

数据库交互

把抓取的数据保存到数据库,sqlite数据库是一个db文件,可以用DBeaver工具打开,很方便

import sqlite3class DBC:def __init__(self, dbname):self.db = dbnameself.conn = Nonedef __enter__(self):self.conn = sqlite3.connect(self.db)return self.conndef __exit__(self, exc_type, exc_val, exc_tb):if exc_type is not None:self.conn.rollback()print("rollback")print(exc_type, exc_val, exc_tb)else:self.conn.commit()self.conn.close()def insert2db(data):with DBC('anjuke.db') as conn:cur = conn.cursor()cur.executemany("""insert into anjuke(community_name,year,address, tags, price, if_down, percent) values(?,?,?,?,?,?,?)""", data) with DBC('anjuke.db') as conn:cur = conn.cursor()cur.execute("""drop table if exists anjuke""")cur.execute("""create table if not exists anjuke(id INTEGER primary key  AUTOINCREMENT not null,community_name TEXT,year TEXT,address TEXT,tags TEXT,price TEXT,if_down BOOL,percent TEXT)""")

selenium 爪巴虫

import time
import traceback
from selenium import webdriverbrowser = webdriver.Chrome()
def process(url):browser.get(url)html = browser.page_sourcehtml = BeautifulSoup(html,)As = html.find_all("a", {"class": "li-row"})if len(As) == 0:raise Exception("EMPTY")data = []for A in As:price = A.find("div", {"class": "li-side"})price_value = price.find("div", {"class": "community-price"})if price_value:price_value = price_value.text.strip()minus = price.find("span")if minus:minus = 'propor-green' in minus.attrs['class']percent = price.find("span")if percent:percent = percent.text.strip()info = A.find("div", {"class": "li-info"})community_name = info.find("div", {"class": "nowrap-min li-community-title"}).textyear = info.find("span", {"class": "year"})if year:year = year.textadvantage =info.find("div", {"class":"prop-tags"})if advantage:advantage = advantage.text.strip()address = info.find("div", {"class": "props nowrap"}).find_all("span")[-1].textdata.append((community_name,year,address, advantage, price_value, minus, percent))insert2db(data)i = 0
while i < 50:  # 超过50显示重复数据i += 1url = f'https://hangzhou.anjuke.com/community/o8-p{i}'  # o2,o4,o6,o8不同排序条件print(url)try:process(url)except Exception as e:traceback.print_exc()s = input("check:")  # 抓取过程中,可能需要输入验证码i = i-1time.sleep(0.5)
http://www.yayakq.cn/news/360510/

相关文章:

  • 制作公司工作网站域名怎么卖
  • 绿色电器公司网站psd模板北京网站seo设计
  • 下载网站后怎么做的网站挖掘工具
  • 上海网站建设选缘魁-企查淄博网站制作企业营销
  • 东莞电商建站软件制作app
  • 虚拟主机销售网站电商创业
  • 如何自己做外贸网站洛阳住房和城乡建设厅网站
  • 青岛建站公司电话现在公司做各网站要多少钱
  • 宝安医院网站建设定制网站和模板网站及仿站的区别
  • 则么做网站注册帐号
  • 网站排名关键词wordpress修改注册
  • 投资网站开发铁总建设函网站
  • 网站制作公司制作网站慈溪网站优化
  • 公司手机版网站制作微营销app
  • 坪地网站建设包括哪些wordpress 获取导航栏
  • 网站导航页面制作网络营销是什么的产生主要源于网络市场的复杂性
  • html5 手机网站开发叫才怎样开一个小贸易公司
  • 江山市建设厅网站网站开发外包网站
  • 如何用ppt做网站太原手机微网站建设
  • saas建站工具库存管理软件手机版
  • 做搜狗pc网站软件百度移动端优化
  • 网站建设和维护费怎么摊销百度竞价广告
  • 南宁网站定制开发网站logo设计制作
  • 品牌建设公司网站推广平台软件有哪些
  • 企业网站开发知名品牌有哪些网络营销制度课完整版
  • 优化网站加载速度泉州专业做网站
  • 网站后台密码忘记了怎么办禹城市建设局网站
  • 网站建设中的pv指的是啥2022最新时事新闻及点评
  • 卓越科技建站无锡做网站网站建设sem
  • 广西seo网站地址链接怎么生成