flutter与python怎样结合?
flutter可以通过以下的方式实现结合:网页请求,网页内容解析,集合数据和保存数据库,
1、#!/usr/bin/python
# coding=utf-8
import platform
from selenium import webdriver
class BaseRequest:
def get_web_content(self, url):
#chromedriver = "C:Program Files (x86)GoogleChromeApplicationchromedriver.exe"
chromedriver = "/Users/zxl/Downloads/chromedriver"
sysstr = platform.system()
if sysstr == 'Darwin':
chromedriver = "/Users/zxl/Downloads/chromedriver"
elif sysstr == 'Windows':
chromedriver = "D:\my_github_workspace\chromedriver.exe"
elif sysstr == 'Linux':
chromedriver = "/Users/zxl/Downloads/chromedriver"
# 创建chrome参数对象
opt = webdriver.ChromeOptions()
# 把chrome设置成无界面模式,不论windows还是linux都可以,自动适配对应参数
opt.set_headless()
prefs = {"profile.managed_default_content_settings.images": 2}
opt.add_experimental_option("prefs", prefs)
# 创建chrome无界面对象
driver = webdriver.Chrome(executable_path=chromedriver, options=opt)
driver.get(url)
return driver
2、#!/usr/bin/python
# coding=utf-8
import datetime
import hashlib
import re
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from com_zxl_spider_db.JokeDB import JokeDB
from com_zxl_spider_request.BaseRequest import *
from com_zxl_spider_data.JokeBean import *
class RequestQsbkTxt(BaseRequest):
def __init__(self):
global jokeDB
jokeDB = JokeDB()
def parse(self, end_url, index):
print "parse::end_url = ", end_url, "::index = ", index
driver = self.get_web_content("https://www.qiushibaike.com/" + end_url + str(index))
elem1 = WebDriverWait(driver, 10).until(
expected_conditions.presence_of_element_located((By.XPATH, '//ul[@]')))
print "elem1 = ", elem1
elem2 = WebDriverWait(driver, 10).until(
expected_conditions.presence_of_element_located((By.XPATH, '//div[@]')))
print "elem2 = ", elem2
# page_source = driver.page_source
isFindNextPage = False
paginationObject = driver.find_element_by_xpath('//ul[@]')
pageListObject = paginationObject.find_elements_by_xpath('.//li')
for pageItemObject in pageListObject:
page_index_txt = pageItemObject.text
print "pageItemObject::page_index_txt = ", page_index_txt
itemFindResult = re.findall(".*?(d+).*?", page_index_txt)
print "pageItemObject::itemFindResult = ", itemFindResult
if len(itemFindResult) > 0:
if int(itemFindResult[0]) > index:
index = int(itemFindResult[0])
isFindNextPage = True
break
# if index - int(itemFindResult[0]) == 1:
# index = int(itemFindResult[0])
# isFindNextPage = True
# break
print "parse::isFindNextPage = ", isFindNextPage, "::index = ", index, "::end_url = ",
hotPicJokeItemPath = '//div[@]'
hotPicJokeItems = driver.find_elements_by_xpath(hotPicJokeItemPath)
print 'hotPicJokeItems length = ', len(hotPicJokeItems)
for hotPicJokeItem in hotPicJokeItems:
jokeId = hotPicJokeItem.get_attribute('id')
md5Object = hashlib.md5()
md5Object.update(jokeId.encode('utf-8'))
jokeMd5Value = md5Object.hexdigest()
authorObject = hotPicJokeItem.find_element_by_xpath('.//div[@]')
authorNickObject = authorObject.find_element_by_xpath('.//h2')
authorNickName = authorNickObject.text
authorImgObject = authorObject.find_element_by_xpath('.//img')
authorImgUrl = authorImgObject.get_attribute('src')
authorGender = ''
authorAge = -1
try:
authorGenderObject = authorObject.find_element_by_xpath(".//div[starts-with(@class,'articleGender')]")
authorGender = authorGenderObject.get_attribute('class')
authorAge = authorGenderObject.text
except NoSuchElementException as e:
print e
contentObject = hotPicJokeItem.find_element_by_xpath('.//div[@]')
content = contentObject.text
thumbImgUrl = ''
try:
thumbObject = hotPicJokeItem.find_element_by_xpath('.//div[@]')
thumbImgObject = thumbObject.find_element_by_xpath('.//img')
thumbImgUrl = thumbImgObject.get_attribute('src')
except NoSuchElementException as e:
print e
statsVoteContent = ''
statsCommentContent = ''
statsCommentDetailUrl = ''
try:
statsObject = hotPicJokeItem.find_element_by_xpath('.//div[@]')
try:
statsVoteObject = statsObject.find_element_by_xpath('.//span[@]')
statsVoteContent = statsVoteObject.text
except NoSuchElementException as e:
print e
try:
statsCommentObject = statsObject.find_element_by_xpath('.//span[@]')
statsCommentContent = statsCommentObject.find_element_by_xpath(
'.//a[@]').text
statsCommentDetailUrl = statsCommentObject.find_element_by_xpath(
'.//a[@]').get_attribute('href')
except NoSuchElementException as e:
print e
except NoSuchElementException as e:
print e
# print authorNickName
# print authorGender
# print authorAge
# print authorImgUrl
# print content
# print thumbImgUrl
# print statsVoteContent
# print statsCommentContent
# print statsCommentDetailUrl
# print jokeId
# print jokeMd5Value
# print 'n'
# print '======================================end=========================================='
# print 'n'
joke_bean = JokeBean()
joke_bean = joke_bean.create_joke_bean(
authorNickName.encode('utf-8'),
authorGender,
authorAge,
authorImgUrl,
content.encode('utf-8'),
thumbImgUrl,
statsVoteContent,
statsCommentContent,
statsCommentDetailUrl,
jokeMd5Value)
isExistJokeItem = jokeDB.query_by_md5(jokeMd5Value)
print isExistJokeItem
if isExistJokeItem is None:
print "not ExistJokeItem"
jokeDB.insert_joke(joke_bean)
else:
print "ExistJokeItem"
driver.close()
return
print "==============end================="
print "n"
driver.close()
if not isFindNextPage:
return
else:
self.parse(end_url, index)
def clas_db(self):
if jokeDB is not None:
jokeDB.close_db()
def start_task(self):
print "start_task::", 'Now Time::', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.parse("pic/page/", 1)
self.clas_db()
if __name__ == "__main__":
request = RequestQsbkTxt()
# request.parse("pic/page/", 1)
request.parse("pic/page/", 1)
request.clas_db()
3、#!/usr/bin/python
# coding=utf-8
class JokeBean:
def create_joke_bean(self,
author_nick_name,
author_gender,
author_age,
author_img_url,
content,
thumb_img_url,
stats_vote_content,
stats_comment_content,
stats_comment_detail_url,
md5):
bean = {'author_nick_name': author_nick_name,
'author_gender': author_gender,
'author_age': author_age,
'author_img_url': author_img_url,
'content': content,
'thumb_img_url': thumb_img_url,
'stats_vote_content': stats_vote_content,
'stats_comment_content': stats_comment_content,
'stats_comment_detail_url': stats_comment_detail_url,
'md5': md5}
return bean。
- 1佛山pc扩散板厂(扩散板生产线)
- 2湛江扩散板材厂家电话地址(湛江板房厂)
- 3亚克力导光板灯饰(亚克力导光板灯饰效果图)
- 4液晶电视均光板导光板(液晶电视均光板导光板区别)
- 5热压导光板项目(导光板热压机操作规程)
- 6tv扩散板使用的原材料(扩散板是什么材料做的?)
- 7包含屏幕显示器扩散板材厂家的词条
- 8如何选择入宅和搬家吉日?寻找最佳时机助您美满生活
- 9bilibili稍后播放怎么不自动(为什么bilibili播放自动暂停)
- 10电磁波扩散板的作用是什么(电磁波扩散板的作用是什么呢)
- 11扩散板涂覆工艺有哪些(扩散板用什么材料好)
- 12东阳三角扩散板(东阳三角扩散板专卖店)
- 13显示器导光板厂商价格多少(液晶屏幕导光板)
- 14揭秘古董家具行业:潜在投资与文化价值的无限魅力
- 152014年家居行业薪酬调查:行业人才稀缺,薪酬水平稳步上升
- 16石家庄搬家公司推荐,专业服务,确保顺利搬迁
- 17搬家吉日选择指南,几点最佳?
- 18民航湖南安全监督管理局待遇怎么?
- 19花小猪行程自动分享(花小猪行程记录可以删吗)
- 20隐藏分多少算高(隐藏分多少合适)
- 21听音室扩散板怎样设计(听音室扩散板安装位置图)
- 22家具行业营销策划:如何打造成功的营销计划
- 23梦幻碎甲刃多少钱(梦幻西游碎甲刃对任务怪有用吗?)
- 24四川防刮花pc扩散板哪家便宜的简单介绍
- 25纳米UGR扩散板(纳米光扩散剂)
- 26极品乐音的扩散板作用(音响扩散板的分类)
- 27珠海激光导光板与印刷(珠海激光导光板行业)
- 28用竹子做扩散板好吗视频的简单介绍
- 29直下式扩散板均匀度的改善(扩散板位置)
- 30东莞亚克力扩散板哪里买(东莞市亚克力制品)