https://opensourceforu.com/2017/10/splinter-easy-way-test-web-applications/
https://splinter.readthedocs.io/en/latest/index.html
https://sites.google.com/a/chromium.org/chromedriver/home
下载谷歌浏览器版本对应的chromedriver.exe并将其加入环境变量path中
Anaconda3 (64-bit)
打开Anaconda Prompt,运行以下命令
jupyter nbconvert --to html your_notebook_name.ipynb
可将ipynb格式文件转换为html格式
(base) C:\Users\DZL>jupyter nbconvert --to html Untitled40.ipynb
[NbConvertApp] Converting notebook Untitled40.ipynb to html
[NbConvertApp] Writing 361412 bytes to Untitled40.html
打开当前工作目录,中间有空格
(base) C:\Users\DZL>start .
或者在Jupyter Notebook开python页面中输入pwd 或者cd
jupyter notebook --help-all
txt = ",,,,,rrttgg.....banana....rrr"
x = txt.strip(",.grt")
print(x)
>>> banana
- from selenium import webdriver
- # 添加驱动
- driver = webdriver.Chrome(r'D:\chromedriver')
- driver.get('https://www.kuaikanmanhua.com/web/topic/1338/')
- #driver.page_source
- #TopicItem cls
- from bs4 import BeautifulSoup
- import requests
- import time
- import os
- soup = BeautifulSoup(driver.page_source, 'lxml')
- #x=soup.select_one('.TopicList').get('TopicItem cls')
- for i in soup.find_all("div", class_="title fl"):
- if i.a['href'] !='javascript:void(0);':
- name = i.text.strip()
- url = 'https://www.kuaikanmanhua.com/'+ i.a['href']
- os.mkdir(r'C:\Users\DANG\Pictures\海贼王\{}'.format(name))
- driver.get(url)
- soup = BeautifulSoup(driver.page_source, 'lxml')
- #soup.find_all('img')
- imglist = soup.select_one(".imgList")
- # enumerate返回可迭代对象,元素为两元元组,进而可以用切片获取
- for img in enumerate(imglist, start=1):
- id_num = img[0]
- imgurl = img[1].get('data-src')
- headers ={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'}
- res = requests.get(imgurl, headers=headers)
- with open(r'C:\Users\DANG\Pictures\海贼王\{}\{}.jpg'.format(name, id_num), 'wb') as f:
- f.write(res.content)
- time.sleep(3)
# 打开图片
from PIL import Image
Image.open("test.jpg")
for i in soup.find_all(class_="ListPicM"):
img_name = re.sub('[?:\\\/\n]', ' ', i.text)
img_url = i.img.get('src')
# img_name = img_url.split('/')[-2]
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'}
try:
res = requests.get(img_url, headers=headers, timeout=500)
except requests.exceptions.ConnectionError:
print('图片{}因超时无法下载,链接为:{}'.format(img_name, img_url))
continue
from splinter import Browser # 如果您没有为该Browser功能提供任何驱动程序参数,则默认firefox将使用 with Browser('chrome') as browser: # Visit URL url = "http://www.google.com" browser.visit(url) browser.fill('q', 'splinter - python acceptance testing for web applications') # Find and click the 'search' button button = browser.find_by_name('btnG') # Interact with elements button.click() if browser.is_text_present('splinter.readthedocs.io'): print("Yes, the official website was found!") else: print("No, it wasn't found... We need to improve our SEO techniques") # imports the Browser library for Splinter from splinter import Browser # takes the email address from user as input to login to his/her Facebook account user_email = input("enter users email address:") # takes the password from user as input to login to his/her Facebook account user_pass = input("enter users password:") # loads the Chrome browser browser= Browser('chrome') # stores the URL for Facebook in url variable url = "https://www.facebook.com/" # navigates to facebook website and load that in the Firefox browser browser.visit(url) # checks if Facebook web page is loaded else prints an error message if browser.is_text_present('www.facebook.com'): # fills the user’s email ID and password in the email and password field of the facebook login section # Inbuilt function browser.fill uses the tag name for Email and Password input box i.e. email and pass respectively to identify it browser.fill('email', user_email) browser.fill('pass', user_pass) # selects the login button using its id value present on the Facebook page to click and log in with the given details button = browser.find_by_id('u_0_d') button.click() else: print("Facebook web application NOT FOUND")
评论
发表评论