无码人妻A片一区二区三区_18禁裸乳无遮挡啪啪无码免费_91精品亚?影视在线?看_人人妻人人爽人人澡AV_国产精品人妻一区二区三区四区_午夜免费影视

中培偉業IT資訊頻道
您現在的位置:首頁 > IT資訊 > 軟件研發 > 如何使用Python構建打字機器人,以及進行Web抓取

如何使用Python構建打字機器人,以及進行Web抓取

2020-08-27 17:46:37 | 來源:中培企業IT培訓網

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

  一、如何使用Python構建打字機器人

先決條件

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進行Web抓取

僅需9行代碼即可使用Python進行Web抓取。

先決條件

如果還沒有安裝,請安裝beautifulsoup4和請求。

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']

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

要檢查您是否正確執行了該操作,數據輸出應類似于以下內容:

{'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抓取功能很棒,當您想從網站中快速提取數據時,可以節省大量時間。上面的示例可幫助您快速入門。

好了以上就是關于如何使用Python構建打字機器人,以及進行Web抓取的全部內容介紹,想了解更多關于Python的信息,請繼續關注中培偉業。

主站蜘蛛池模板: 宅男色影视亚洲人在线 | 农民工嫖妓50岁老熟女 | 久久精品视频中文字幕 | 亚洲精品欧美精品 | 国产精品小黄鸭一区二区三区 | 人妻被粗大猛进猛出国产 | 日日碰狠狠躁久久躁蜜桃 | 日日操日日 | 欧美人成在线视频 | 毛片在线视频 | 调味的房子在线观看 | 欧美日韩高清免费 | 久久久久久精品无码午夜按摩师 | 亚洲乱码国产乱码精品精 | 国产精品嫩草研究院 | 高大丰满40岁东北少妇 | 国产三级黄色录像 | 日韩中文字幕视频在线 | 日韩专区第一页 | 视频精品久久 | 中文字幕的av | porno俄罗斯 久久久短视频 | 欧美日韩一区二区高清 | 久久久久久极品 | 小强精品辣文小说网 | 无码丰满熟妇JULIAANN与黑人 | 中文无码乱人伦中文视频在线V | 五月丁香六月婷婷国产视频96视频 | 熟妇人妻无码中文字幕 | 2020亚洲午夜无码天堂 | 国产片在线观看.com | 免费的又色又爽又黄的片 | 18禁无遮挡无码网站免费 | 免费人成视频19674不收费 | 日日碰狠狠丁香久燥 | 国产伦精品一区二区三区 | 免费一级欧美片在线观看网站 | 亚洲精品久久久久久久观小说 | 天天摸夜夜摸爽爽狠狠婷婷97 | 无码AV免费一区二区三区四区 | 久久亚洲久 |