日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python扇贝单词书_Python脚本 扇贝单词书爬取

發布時間:2023/12/15 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python扇贝单词书_Python脚本 扇贝单词书爬取 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是一個·用于爬取扇貝單詞書的腳本

將在.py文件目錄得到一個名為out.txt的輸出文件

主要使用了selenium庫(webdriver)

使用方式:

更改

13行中指向webdriver驅動器 代碼中使用了firefox提供的驅動器

Path = r’C:\Users\pc\Downloads\geckodriver-v0.19.1-win64\geckodriver.exe’

15行中的單詞書網頁根目錄

rootdir=“https://www.shanbay.com/wordbook/6403/”

運行,并且贊美太陽

source code:

# coding=utf-8

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.ui import Select

from selenium.common.exceptions import NoSuchElementException

from selenium.common.exceptions import NoAlertPresentException

import unittest, time, re

import sys

reload(sys)

sys.setdefaultencoding('utf-8')

Path = r'C:\Users\pc\Downloads\geckodriver-v0.19.1-win64\geckodriver.exe'

f = open("out.txt", "w")

rootdir=“https://www.shanbay.com/wordbook/6403/”

class ShanbeiWord(unittest.TestCase):

def setUp(self):

self.driver = webdriver.Firefox(executable_path=Path)

self.driver.implicitly_wait(30)

self.verificationErrors = []

self.accept_next_alert = True

def test_shanbei_word(self):

s = " "

driver = self.driver

i = 1

while i<12:

driver.get(

driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/div/div[4]/div[7]/div["+str(i)+"]/div[1]/table/tbody/tr/td[1]/a").click()

i=i+1

j=1

while j<10:

#f.write(driver.page_source)

s = str(s)

s=s+str(driver.page_source)

#f.write(str(i)+"+++"+str(j))

driver.find_element_by_link_text(">").click()

j=j+1

print(str(i) + "+++" + str(j))

#f.write(driver.page_source)

s=str(s)

s = s + str(driver.page_source)

s = str(re.findall(r'g>.*', s, flags=0))

s = str(re.findall(r'>.*?<', s, flags=0))

f.write(s)

def is_element_present(self, how, what):

try:

self.driver.find_element(by=how, value=what)

except NoSuchElementException as e:

return False

return True

def is_alert_present(self):

try:

self.driver.switch_to_alert()

except NoAlertPresentException as e:

return False

return True

def close_alert_and_get_its_text(self):

try:

alert = self.driver.switch_to_alert()

alert_text = alert.text

if self.accept_next_alert:

alert.accept()

else:

alert.dismiss()

return alert_text

finally:

self.accept_next_alert = True

def tearDown(self):

self.driver.quit()

self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":

unittest.main()

贊過:

贊 正在加載……

相關

總結

以上是生活随笔為你收集整理的python扇贝单词书_Python脚本 扇贝单词书爬取的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。