1 Star 1 Fork 5

巴挂/爬虫-1688商品详情数据

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pagination.py 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
gebinda 提交于 2021-07-08 18:27 . 重构
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
import requests
from time import sleep
from lxml import etree
from config import url,proxy,is_window,sleep_time
from file import set_url_list,get_url_list
# 获取浏览器对象
def get_browser():
option = ChromeOptions()
# 关闭自动控制
option.add_experimental_option('excludeSwitches', ['enable-automation', 'enable-logging'])
option.add_experimental_option('useAutomationExtension', False)
# 代理IP
BG_proxy = requests.get(proxy).text
option.add_argument("--proxy-server=" + BG_proxy)
# 是否显示浏览器
if not is_window:
option.add_argument('--headless')
option.add_argument('--disable-gpu')
# 干掉全局变量
browser = webdriver.Chrome(options=option)
browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
})
return browser
web = get_browser()
goods_list = []
def get_pagination(pageNum, total=10):
web.get(url)
tab_url = web.find_elements_by_xpath('//*[@id="search-bar"]/div[2]/div/div/div/ul/li/div[1]/a')
arr = []
for item in tab_url:
arr.append(item.get_attribute('href'))
print("获取第" + str(pageNum) + "页地址成功")
sleep(2)
pageNum += 1
if pageNum <= total:
next_page = web.find_elements_by_xpath('//*[@class="next"]')
next_page[0].click()
get_pagination(pageNum,total)
else:
web.quit()
get_pagination(1)
set_url_list(goods_list)
arr = get_url_list()
for item in arr:
print(len(item))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/baguLoveLHY/crawler-1688-product-details.git
git@gitee.com:baguLoveLHY/crawler-1688-product-details.git
baguLoveLHY
crawler-1688-product-details
爬虫-1688商品详情数据
master

搜索帮助