设为首页 - 加入收藏 华夏网 (http://www.hxwgxz.com)- 云主机,资讯,互联网,人工智能,云计算,大数据,区块链,VR,站长网!
热搜: 2019 google 中国 2020
当前位置: 主页 > 电商 > 正文

通过win32api与win32con模拟按键精灵爬取中国商标网数据

发布时间:2021-02-25 14:15 所属栏目:[电商] 来源:网络整理
导读:# -*- coding: utf-8 -*- # Author: Yakuho # Date : 2019/8/8 import asyncio import os import time import random from selenium import webdriver import button import win32api import win32con import queue # id_q = (x for x in range(int(input(‘

# -*- coding: utf-8 -*-
# Author: Yakuho
# Date  : 2019/8/8
import asyncio
import os
import time
import random
from selenium import webdriver
import button
import win32api
import win32con
import queue
# id_q = (x for x in range(int(input(‘想要爬取的起始注册号:‘)),int(input(‘想要爬取的最后注册号:‘)) + 1))
info_q = queue.Queue()


class Detail:
    def __init__(self):
        self.url = ‘http://sbj.cnipa.gov.cn/‘
        self.executable_path = os.path.abspath(‘chromedriver.exe‘)
        self.options = webdriver.ChromeOptions()
        self.options.add_argument(‘--disable-gpu‘)
        self.options.add_experimental_option(‘excludeSwitches‘,[‘enable-automation‘])
        # self.options.add_argument(‘proxy-server=‘ + proxy)
        self.browser = webdriver.Chrome(executable_path=self.executable_path,options=self.options)
        self.position = (0,0)

    async def brand_check(self):
        self.browser.set_script_timeout(4)
        self.browser.set_page_load_timeout(4)
        try:
            self.browser.get(self.url)
        except:
            pass
        win32api.SetCursorPos((0,0))
        # 商标查询
        for i in button.button1:
            win32api.SetCursorPos(i)
            time.sleep(random.randint(2,4) * 0.001)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0)
        self.browser.close()  # 关闭第一个页面
        await asyncio.sleep(4)
        # 我同意
        for i in button.button2:
            win32api.SetCursorPos(i)
            time.sleep(random.randint(2,0)
        await asyncio.sleep(4)
        # 综合查询
        for i in button.button3:
            win32api.SetCursorPos(i)
            time.sleep(random.randint(2,0)
        await asyncio.sleep(6)

    async def main(self):
        await self.brand_check()
        infos = [‘135001‘,‘1350001‘]
        for info in infos:
            # info = id_q.get()
            # 点击输入框
            win32api.SetCursorPos((426,415))
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0)
            # 清空文本框
            win32api.keybd_event(17,0)
            win32api.keybd_event(65,0)
            win32api.keybd_event(17,win32con.KEYEVENTF_KEYUP,0)
            win32api.keybd_event(8,0)
            # 输入识别号
            for i in info:
                win32api.keybd_event(ord(i),0)
                win32api.keybd_event(ord(i),0)
            # 点击查询
            for i in button.button4_click:
                win32api.SetCursorPos(i)
                time.sleep(random.randint(2,4) * 0.001)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0)
            # 点击查询的项目
            win32api.SetCursorPos((126,202))  # 输入框位置
            await asyncio.sleep(4)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0)
            if self.browser.window_handles[-2] == 2:
                self.browser.switch_to.window(self.browser.window_handles[-1])
                self.browser.close()
            else:
                await asyncio.sleep(4)
                self.browser.switch_to.window(self.browser.window_handles[-2])
                print(self.browser.page_source)
                # info_q.put(self.browser.page_source)
                self.browser.close()
                self.browser.switch_to.window(self.browser.window_handles[-1])
                self.browser.close()


if __name__ == "__main__":
    progress1 = Detail()
    # progress2 = Detail()
    tasks = [progress1.main()]
    asyncio.get_event_loop().run_until_complete(asyncio.gather(*tasks))
# -*- coding: utf-8 -*-
# Author: Yakuho
# Date  : 2019/8/9
button1 = [(0,1),(0,2),3),5),9),(1,12),16),(2,18),20),21),24),(2,25),26),29),32),(3,35),39),41),(5,45),(6,51),(7,55),(8,58),(9,62),(11,70),71),(14,78),(16,82),(22,89),(23,96),(27,101),(28,106),(30,110),(31,113),(32,118),(34,124),(37,130),(40,137),(43,144),(47,153),(50,160),(53,168),(57,175),(62,183),(66,189),(69,196),(71,200),(75,206),(78,212),(82,218),(86,227),229),(87,233),(89,240),(91,247),(96,253),(101,261),(105,268),(108,274),(112,282),(117,289),(124,297),(129,306),(133,315),(139,324),(144,333),(149,342),(155,353),(160,362),(164,371),(168,381),(170,388),(173,397),(175,403),(177,410),(181,419),(185,428),(187,435),(191,442),(193,450),(197,459),(202,468),(206,477),(209,485),(211,496),(213,504),(215,512),(218,520),(220,529),(224,538),(228,547),(230,554),(233,563),(235,570),(237,577),(239,583),(240,588),(241,595),(243,604),(244,611),618),626),631),(247,639),(248,640),(249,643),(250,646),(252,654),655),(256,667),671),(256,677),687),690),695),699),(259,703),(263,708),(264,713),(267,717),(268,723),(271,727),(272,734)]
button2 = [(270,743),(273,(274,(275,(278,742),(281,742),(281,(284,741),(290,740),(293,739),(294,(298,738),(302,736),(306,735),(308,734),(310,(313,(316,(318,(321,(324,734),(326,(329,733),(332,732),(337,731),(342,730),(346,(350,728),(355,727),(355,(359,(362,726),(366,(371,725),(375,(379,725),(382,724),(386,(390,(395,722),(398,(401,(402,721),(406,720),(409,720),(411,(413,719),(416,718),(419,(424,(427,718),(430,(434,716),(437,715),(440,714),(441,(442,(445,714),(449,713),(450,(453,(457,712),(459,(462,(463,711),(465,711),(467,710),(470,709),(471,(474,(477,707),(481,706),(482,706),(482,(483,(485,705),(486,704),(488,702),(489,(490,(491,702),(494,700),(494,(495,(498,698),697),697),(499,696),(499,(502,694),(504,(506,693),(509,692),(509,690),(510,(511,(512,688),(513,687),(513,687)]
button3 = [(512,682),(514,678),676),(515,674),(517,670),(518,668),(519,667),(520,663),(521,662),(522,660),(523,658),(525,(526,651),647),(527,642),(527,(528,641),635),(529,634),(531,629),625),(532,622),622),(533,(534,615),610),(535,606),(536,602),598),(537,595),(538,591),(538,590),587),582),578),577),573),(540,569),(541,567),(541,564),562),561),(542,555),551),(542,549),546),543),(543,541),(545,536),534),(545,531),(546,530),526),523),521),518),(547,517),(548,514),(548,512),511),509),506),503),499),(549,498),(549,495),(550,492),490),486),485),(550,484),481),479),478),476),(551,474),474),(551,473),471),(552,470),467),466),466),(552,(553,465),463),462),(554,461)]
button4_click = [(426,415),(426,420),(428,425),(429,427),(431,431),433),(435,437),440),(437,440),(439,446),451),455),460),(444,465),(446,(446,(447,(448,(449,(450,(452,493),(454,494),(455,(456,497),500),(458,500),(458,502),505),510),(463,515),(464,(466,522),(467,524),(468,527),(472,(473,531),(473,534),535),(475,540),549),552),(484,558),559),560),564),(486,566),(487,568),569),571),575),579),(490,585),586),592),600),602),(492,(492,608),613),616),619),621),623),623),628),630),633),637),(496,638),(500,644),644),(500,(501,645),645)]
button4_check = [(501,642),(498,(496,637),634),619),600),(491,(488,554),535),(474,521),(465,505),494),(454,484),462),(442,(435,415)]
button5 = [(329,454),(330,455),(332,456),(334,458),(335,(337,459),(338,461),(340,463),(342,467),(344,469),(345,470),(347,472),(348,(350,476),(351,478),(352,479),(353,480),481),483),(357,(359,(361,(363,486),(365,487),488),(366,490),(367,(369,(371,(373,491),(375,493),(376,(379,(380,(381,496),498),(383,(384,501),(385,502),(388,504),(389,(390,506),507),(392,508),(393,510),514),516),(395,518),519),(396,523),525),(397,526),(399,528),(401,530),532),(402,536),(404,538),(405,(406,539),(407,541),543),(411,(412,545),(413,547),(414,548),(415,550),(417,(418,553),(419,556),(421,(422,(423,558),(425,560),(426,562),(428,(432,565),(433,566),(434,567),(439,(441,(443,570),572),(445,573),575),(447,581),583),585),(452,(453,587),589),590),592),(456,593),(457,596),(459,(461,597),(462,(464,598),601),(466,603),(468,604),(470,(471,606),607),609),611),(475,613),(477,614),(479,(481,(483,615),(484,617),(485,618),(487,621),(489,624),625),627),628),630),(493,632),(495,635),(497,639),640),641),(502,(504,(506,(508,(510,645),(511,647),]

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

网友评论
推荐文章