欧美麻豆久久久久久中文_成年免费观看_男人天堂亚洲成人_中国一级片_动漫黄网站免费永久在线观看_国产精品自产av一区二区三区

中培偉業(yè)IT資訊頻道
您現(xiàn)在的位置:首頁 > IT資訊 > 軟件研發(fā) > 如何使用Python構(gòu)建打字機(jī)器人,以及進(jìn)行Web抓取

如何使用Python構(gòu)建打字機(jī)器人,以及進(jìn)行Web抓取

2020-08-27 17:46:37 | 來源:中培企業(yè)IT培訓(xùn)網(wǎng)

眾所周知,Python作為編程語言的一種,不僅語法簡單、易學(xué)并且很有前途,很多人都對(duì)Python感興趣。Python的應(yīng)用十分廣泛。經(jīng)常關(guān)注我的朋友可能知道,關(guān)于Python的使用,之前已經(jīng)為大家介紹了很多用法,今天主要介紹兩個(gè)方面的內(nèi)容,一個(gè)是如何使用Python構(gòu)建打字機(jī)器人,另一是如何使用Python進(jìn)行Web抓取的內(nèi)容。

  一、如何使用Python構(gòu)建打字機(jī)器人

先決條件

pip install selenium

代碼段

# Importing required modules and initializing variablesfrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimport re

string = ''

# ______________________________________

# Opening thetypingcat.com on firefox

firefox = webdriver.Firefox()

firefox.get

# ______________________________________

# Using javascript to get the typing content from the website and storing value in "string" variablefor i in range(firefox.execute_script('return document.querySelectorAll(".line").length')):

string += firefox.execute_script('return document.querySelectorAll(".line")['+str(i)+'].innerHTML')

string = re.sub(r'<[^>]*>','',string) #This line is just delete tags present inside string

# ______________________________________

# Selenium commands to type what is stored inside string variable on the focused screen

action = ActionChains(firefox)

action.send_keys(string)

action.perform()

# ______________________________________ END ______________________________________

  二、如何使用Python進(jìn)行Web抓取

僅需9行代碼即可使用Python進(jìn)行Web抓取。

先決條件

如果還沒有安裝,請(qǐng)安裝beautifulsoup4和請(qǐng)求。

pip install beautifulsoup4

pip install requests

代碼段

import requestsfrom bs4 import BeautifulSoup

result = requests.get

soup = BeautifulSoup(result.content)

links = soup.find_all("a", "title")

data = {}for link in links:

title = link.string

data[title] = link.attrs['href']

這里是完整的代碼段,您可以將其直接復(fù)制并粘貼到終端,收藏的文本編輯器或jupyter筆記本中。

要檢查您是否正確執(zhí)行了該操作,數(shù)據(jù)輸出應(yīng)類似于以下內(nèi)容:

{'MSI GL62VR 7RFX': '/test-sites/e-commerce/allinone/product/326',

'Dell Vostro 15…': '/test-sites/e-commerce/allinone/product/283',

'Dell Inspiron 17…': '/test-sites/e-commerce/allinone/product/296'}

Web抓取功能很棒,當(dāng)您想從網(wǎng)站中快速提取數(shù)據(jù)時(shí),可以節(jié)省大量時(shí)間。上面的示例可幫助您快速入門。

好了以上就是關(guān)于如何使用Python構(gòu)建打字機(jī)器人,以及進(jìn)行Web抓取的全部內(nèi)容介紹,想了解更多關(guān)于Python的信息,請(qǐng)繼續(xù)關(guān)注中培偉業(yè)。

主站蜘蛛池模板: 欧美在线不卡视频 | 无套内射极品少妇chinese | AV无码久久久久久不卡网站 | 老年一级片 | 免费精品一区二区三区第35二区 | 欧美日韩综合 | 伊人久久综合热线大杳蕉 | 苍井苍空A免费井线在线观看 | 久久久久亚洲AV片无码 | 香港台湾经典三级a视频 | 又湿又紧又大又爽A视频国产 | 午夜三级a三级三点 | 色噜噜狠狠一区二区三区果冻 | 老师脱了内裤让我爽了一夜 | 人妻体验按摩到忍不住哀求继续 | 亚洲精品国产精品无码国模 | 96久久精品A片一区二区 | 欧美老人牲交 | vr成人片在线播放网站 | 成人A级毛片免费观看AV | 日本一道高清视频1区 | 色综合色狠狠天天综合网 | 青青草免费在线视频 | 邻居少妇人妻互换 | 免费三级现频在线观看播放 | 把极品白丝班长啪到腿软 | 私人vps毛片| 国产精品色情一区二区三区 | free性欧美人与dog | 亚洲色婷婷久久精品AV蜜桃 | 伊人无码精品久久一区二区 | 成人无码h肉动漫在线观看站 | 让少妇高潮无乱码高清在线观看 | 久久国内精品自在自线 | 久久久久久久无码高潮 | 国产精品人妻无码久久青草 | 人人妻人人做人人爽精品 | CHINESEFREE高潮抽搐 | 18禁勿入午夜网站入口 | 亚洲另类精品国产一级欧美忘忧草 | 美女脱个精光露出尿口视频 |