无码人妻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的信息,請繼續關注中培偉業。

主站蜘蛛池模板: 日本狠狠干 | 亚洲欧美另类久久久精品 | A∨无码人妻系列在线 | 曰韩精品无码一区二区三区 | 一一级毛片 | 欧美乱码一区二区三区 | 免费黄色一级毛片 | 精品二区 | 欧美伊香蕉久久综合网99 | 国内精品久久久久久久久齐齐 | 蜜臀影院| 日本三节片 | 久久久久久久不卡 | 精品国产免费人成在线观看 | 国产午夜福利在线观看红一片 | 另类重口特殊AV无码 | av中文字幕无码免费看 | 国产成人久久婷婷精品流白浆 | 久久99精品久久久久久噜噜 | 精品精品 | 亚洲高清视频在线观看 | 亚洲麻豆国产 | 欧美综合视频在线观看 | 国产熟睡乱子伦午夜视频 | av中文字幕一区二区三区 | 国产成人综合在线观看 | 亚洲精品区无码欧美日韩 | 和小三爽到喷水h | 国产a免费视频 | 性盈盈网站久久久久忘忧草 | 国产偷国产偷亚洲高清日韩 | 亚洲综合久久成人AV | 日本一区二区三区免费A片 精品乱人码一区二区二区 a级免费网站 | 一级做a爰片久久毛片16 | 性8sex8亚洲网友自拍 | 办公室艳妇潮喷视频 | 欧美日韩一区二区三区在线看黄 | 成人碰碰| 日韩AV无码社区一区二区三区 | 红果免费看 | 激情亚洲一区二区三区四区 |