资源简介
:爬取网站数据,基于 selenium.webdriver
代码片段和文件信息
__author__ = ‘fandechun‘
import datetime
import re
import sys
import time
import uuid
import pymysql
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
def find_element(driverlocater):#封装WebDriverWait.until方法
element=WebDriverWait(driver 10 0.5).until(EC.presence_of_element_located(locater))
return element
def isElementExist(driverxpath1):
flag=True
try:
driver.find_element_by_xpath(xpath1)
return flag
except:
flag=False
return flag
def get_by_xpath_if_existed(driverxpath1):
try:
driver.find_element_by_xpath(xpath1)
return driver.find_element_by_xpath(xpath1)
except:
return ‘未定‘
def get_by_class_if_existed(drivercolumn):
try:
driver.find_element_by_class_name(column)
return driver.find_element_by_class_name(column)
except:
return ‘未定‘
def get_by_id_if_existed(drivercolumn):
try:
driver.find_element_by_id(column)
return driver.find_element_by_id(column)
except:
return ‘未定‘
class MySqlSession:
def __init__(self):
self.con = pymysql.connect(
host=‘localhost‘
port=3306
user=‘root‘
passwd=‘123‘
db=‘python‘
charset=‘utf8‘
)
def insert_house_summary_info(self house_nameother_namehouse_priceaddressopen_datehouse_layouts):
# 数据库游标!
cue = self.con.cursor()
uid = str(uuid.uuid1())
house_id = ‘‘.join(uid.split(‘-‘))
sql=‘insert into d_house_summary values (%s%s%s%s%s%s%s)‘
try:
cue.execute(sql[house_idhouse_nameother_namehouse_priceaddressopen_datehouse_layouts])
except Exception as e:
print(f“插入数据库失败:{e}“)
self.con.rollback()
else:
self.con.commit()
def insert_house_details_info(self house_namebuilding_areahouse_layout):
# 数据库游标!
cue = self.con.cursor()
uid = str(uuid.uuid1())
layout_id = ‘‘.join(uid.split(‘-‘))
sql=‘insert into d_house_details values (%s%s%s%s)‘
try:
cue.execute(sql[layout_idhouse_namebuilding_areahouse_layout])
except Exception as e:
print(f“插入数据库失败:{e}“)
self.con.rollback()
else:
self.con.commit()
browser = webdriver.Chrome()
browser.get(“https://jn.fang.anjuke.com/loupan/“)
########判断页面是否已打开########
locater=(By.ID‘search-btn‘)
find_element(browserlocater)
shouye=browser.current_window_handle
########查询条件########
########这个下拉列表框比较特殊,无法通过正常的方法选择,只能通过模拟鼠标操作来点击。且需要放在最前面,通过点击其它查询条件触发检索########
elemen
- 上一篇:python demo百度文库.py
- 下一篇:NumPy Cookbook
相关资源
- python demo百度文库.py
- Python总结(精简).doc
- Supervised Learning with Python
- python实现一个简单的名片管理系统功
- Python源码剖析.pdf59505
- python语言实现的基于opencv的表针识别
- 基于Python的酒店管理系统
- 打砖块
- python数据结构
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
评论
共有 条评论