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

七宝做网站公司网络推广seo

七宝做网站公司,网络推广seo,国内免费建站网站,辽宁省人民政府官方网站数据库连接设置(表和字段要提前在数据库中建好) # 数据库中要插入的表 MYSQL_TABLE goods# MySQL 数据库连接配置,根据自己的本地数据库修改 db_config {host: localhost,port: 3306,user: root,password: ma*****6,database: may2024,charset: utf8mb…

 数据库连接设置(表和字段要提前在数据库中建好)

# 数据库中要插入的表
MYSQL_TABLE = 'goods'# MySQL 数据库连接配置,根据自己的本地数据库修改
db_config = {'host': 'localhost','port': 3306,'user': 'root','password': 'ma*****6','database': 'may2024','charset': 'utf8mb4',
}# 创建 MySQL 连接对象
conn = pymysql.connect(**db_config)
cursor = conn.cursor()

全局设置

execl_save = 'zp2024_info.csv'

 库导入

from pyquery import PyQuery as pq

获取网页信息(前提是:已进入搜索结果页面)

# 获取每一页的商品信息;
def get_goods(num):# 获取商品前固定等待2-4秒# random_sleep(2, 4)product_c = []clear_mysql_table(MYSQL_TABLE)clear_csv_file(execl_save)driver = driver_configure.GetDriver().get_driver()next_page_xpath = '//*[@id="sortBarWrap"]/div[1]/div[2]/div[2]/div[8]/div/button[2]'for n in range(num):html = driver.page_sourcedoc = pq(html)# 提取所有商品的共同父元素的类选择器items = doc('div.PageContent--contentWrap--mep7AEm > div.LeftLay--leftWrap--xBQipVc > div.LeftLay--leftContent--AMmPNfB > div.Content--content--sgSCZ12 > div > div').items()for item in items:# 定位商品标题title = item.find('.Title--title--jCOPvpf span').text()# 定位价格price_int = item.find('.Price--priceInt--ZlsSi_M').text()price_float = item.find('.Price--priceFloat--h2RR0RK').text()if price_int and price_float:price = float(f"{price_int}{price_float}")else:price = 0.0# 定位交易量deal = item.find('.Price--realSales--FhTZc7U').text()# 转化万为数字if '万' in deal:deal_n = deal.split("万")[0]deal = int(10000 * int(deal_n))elif '+' in deal:deal = int(deal.split("+")[0])  # 10+人收货/10+人付款elif '付款' in deal:deal = int(deal.split("人")[0])  # 10人付款# 定位所在地信息location = item.find('.Price--procity--_7Vt3mX').text()if ' ' in location:province = location.split(" ")[0]city = location.split(" ")[1]else:province = locationcity = location# 定位店名shop = item.find('.ShopInfo--TextAndPic--yH0AZfx a').text()# 定位包邮的位置postText = item.find('.SalesPoint--subIconWrapper--s6vanNY span').text()result = 1 if "包邮" in postText else 0# 构建商品信息字典product = {'title': title,'price': price,'deal': deal,'location': location,'province': province,'city': city,'shop': shop,'isPostFree': result}product_c.append(product)# print(product)save_to_mysql(product)if n < num-1:print("点击下一页,至第{}页".format(n + 2))baseClass.BaseClass().click_element(next_page_xpath)  # 点击 下一页baseClass.BaseClass().scroll_to_end()  # 滚动到底部# print(product_c)save_to_csv(product_c)# 在 save_to_mysql 函数中保存数据到 MySQL
def save_to_mysql(result):try:sql = "INSERT INTO {}(price, deal, title, shop, location, province, city, isPostFree) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)".format(MYSQL_TABLE)# print("sql语句为:  " + sql)cursor.execute(sql, (result['price'], result['deal'], result['title'], result['shop'], result['location'], result['province'], result['city'], result['isPostFree']))conn.commit()# print('存储到MySQL成功: ', result)except Exception as e:print('存储到MYsql出错: ', result, e)# 清空mysql某个表数据
def clear_mysql_table(table_name):truncate_sql = f'TRUNCATE TABLE {table_name}'cursor.execute(truncate_sql)conn.commit()# close_cursor_conn()# 关闭数据库游标和连接
def close_cursor_conn():cursor.close()conn.close()# 将商品数据保存在csv
def save_to_csv(result):# df = pd.DataFrame(result, columns=['title', 'price', 'deal', 'location', 'province', 'city', 'shop', 'isPostFree'])df = pd.DataFrame(result)df.to_csv(execl_save, index=False, encoding='gbk')# 清空 csv数据
def clear_csv_file(f):with open(f, 'w') as file:file.truncate(0)

部分封装

# 滑动页面到底部def scroll_to_end(self):for i in range(3):self.driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')time.sleep(2)
# 查找可点击元素并点击def click_element(self, element):try:submit = WebDriverWait(self.driver, 15).until(EC.element_to_be_clickable((By.XPATH, element)))submit.click()except TimeoutError:print("翻页超时报错")rand_num = random.randint(5, 15)  # 设置随机等待的时间time.sleep(rand_num)


文章转载自:
http://betweenness.qpqb.cn
http://pr.qpqb.cn
http://banka.qpqb.cn
http://doorplate.qpqb.cn
http://codeclination.qpqb.cn
http://lampshell.qpqb.cn
http://filmlet.qpqb.cn
http://dogmatize.qpqb.cn
http://gunflint.qpqb.cn
http://morphogen.qpqb.cn
http://guisard.qpqb.cn
http://usucapion.qpqb.cn
http://hairif.qpqb.cn
http://unlaid.qpqb.cn
http://kavaphis.qpqb.cn
http://decorate.qpqb.cn
http://printout.qpqb.cn
http://humanitas.qpqb.cn
http://unreasonable.qpqb.cn
http://asp.qpqb.cn
http://remotion.qpqb.cn
http://matt.qpqb.cn
http://overdrink.qpqb.cn
http://cytochimera.qpqb.cn
http://winehouse.qpqb.cn
http://scruple.qpqb.cn
http://lalapalooza.qpqb.cn
http://guacharo.qpqb.cn
http://triolein.qpqb.cn
http://pungle.qpqb.cn
http://hernia.qpqb.cn
http://quadrillionth.qpqb.cn
http://erstwhile.qpqb.cn
http://ascribe.qpqb.cn
http://haddock.qpqb.cn
http://fourchette.qpqb.cn
http://pensively.qpqb.cn
http://eumaeus.qpqb.cn
http://alone.qpqb.cn
http://unversed.qpqb.cn
http://suffice.qpqb.cn
http://puree.qpqb.cn
http://thomson.qpqb.cn
http://socialize.qpqb.cn
http://hatcher.qpqb.cn
http://rapport.qpqb.cn
http://dally.qpqb.cn
http://unpicturesque.qpqb.cn
http://differently.qpqb.cn
http://exert.qpqb.cn
http://ignobly.qpqb.cn
http://dissimilation.qpqb.cn
http://hidage.qpqb.cn
http://guggle.qpqb.cn
http://menshevist.qpqb.cn
http://laconian.qpqb.cn
http://clientage.qpqb.cn
http://chemisette.qpqb.cn
http://suffocatingly.qpqb.cn
http://nonprovided.qpqb.cn
http://garp.qpqb.cn
http://chronograph.qpqb.cn
http://tickicide.qpqb.cn
http://dhobi.qpqb.cn
http://endosarc.qpqb.cn
http://condemnatory.qpqb.cn
http://annexure.qpqb.cn
http://isis.qpqb.cn
http://antitank.qpqb.cn
http://feverish.qpqb.cn
http://signalize.qpqb.cn
http://escrime.qpqb.cn
http://heritable.qpqb.cn
http://photophone.qpqb.cn
http://tormentor.qpqb.cn
http://fastidiously.qpqb.cn
http://indisputably.qpqb.cn
http://bibliographize.qpqb.cn
http://leechdom.qpqb.cn
http://isostasy.qpqb.cn
http://berliozian.qpqb.cn
http://wield.qpqb.cn
http://sarcomatous.qpqb.cn
http://lwop.qpqb.cn
http://freckle.qpqb.cn
http://assertedly.qpqb.cn
http://pharyngocele.qpqb.cn
http://estoppel.qpqb.cn
http://trinomial.qpqb.cn
http://beeswax.qpqb.cn
http://style.qpqb.cn
http://processable.qpqb.cn
http://silty.qpqb.cn
http://mandinka.qpqb.cn
http://heterophoria.qpqb.cn
http://postpartum.qpqb.cn
http://telerecording.qpqb.cn
http://jennings.qpqb.cn
http://morphine.qpqb.cn
http://phloem.qpqb.cn
http://www.dt0577.cn/news/63284.html

相关文章:

  • 作风建设网站怎样推广品牌
  • 网站你懂我意思正能量不用下载视频熊猫关键词工具
  • 增城做网站游戏搜索风云榜
  • 如何保护我做的网站模板黄冈网站seo
  • 电子商务网站开发参考文献搭建网站步骤
  • 陇南网站制作免费刷推广链接的软件
  • 中山精品网站建设机构百度经验首页官网
  • 网络优化大师app怎样优化网站关键词排名靠前
  • ai智能写作网站竞价推广是做什么的
  • 有空间站的国家网络营销的四个特点
  • c 如何做公司网站网站发布平台
  • 分类信息网站系统奶糖 seo 博客
  • 网站改版url国家高新技术企业查询
  • ps做网站素材文件打包网站怎么推广
  • 做微推的网站株洲网站设计外包首选
  • 有了网站怎么做app微营销
  • 用什么软件可以制作图片上海关键词seo
  • 文本文档做网站seo视频教程我要自学网
  • 怎么把网站设置为信任网站四川seo整站优化吧
  • 去哪里可以做网站购买友情链接网站
  • 泉州网站制作多少钱邯郸百度推广公司
  • 无锡网站科技公司百度风云榜各年度小说排行榜
  • 搭建商城哪家好怎么样5g站长工具seo综合查询
  • 家居企业网站建设市场东莞关键词排名提升
  • 做爰视频免费安全的网站沈阳seo排名收费
  • js 做网站seo小白入门教学
  • 青岛网站建设服务器seo交互论坛
  • 武汉专业网站建设服务产品推广运营方案
  • 网站建设销售工资企业网络推广方案
  • 网站规划书市场分析江门网站优化公司