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

歡迎訪問 生活随笔!

生活随笔

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

python

python测试工具开发面试宝典3web抓取

發布時間:2025/3/8 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python测试工具开发面试宝典3web抓取 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

用requests輸出網站返回頭

輸出 'https://china-testing.github.io/' 的返回頭

  • 參考答案
In [1]: import requestsIn [2]: url = 'https://china-testing.github.io/'In [3]: response = requests.get(url)In [4]: response.request.headers Out[4]: {'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}

requests是HTTP訪問極其重要的庫,比較常用的屬性有:response.status_code、response.text。

更多參考資料:python工具庫介紹-requests:人性化的HTTP

用Requests和BeautifulSoup爬取博客標題

爬取 https://china-testing.github.io/ 首頁的博客標題,共10條.

  • 參考答案
# -*- coding: utf-8 -*- # 討論釘釘免費群21745728 qq群144081101 567351477 # CreateDate: 2018-10-16import requests from bs4 import BeautifulSoupdef get_upcoming_events(url):req = requests.get(url)soup = BeautifulSoup(req.text, 'lxml')events = soup.findAll('article')for event in events:event_details = {}event_details['name'] = event.find('h1').find("a").textprint(event_details)get_upcoming_events('https://china-testing.github.io/')

執行結果:

$ python3 blogs.py {'name': '接口自動化性能測試線上培訓大綱'} {'name': '2018最佳人工智能圖像處理工具OpenCV書籍下載'} {'name': 'IBM開發社區python精品文章匯總'} {'name': 'python工具庫介紹-requests:人性化的HTTP'} {'name': '中草藥的故事-金銀花(標準中藥)- 清熱解毒,疏散風熱'} {'name': '中草藥的故事-合歡花(標準中藥)'} {'name': '中草藥的故事-吳茱萸(標準中藥)'} {'name': '[雪峰磁針石博客]python3快速入門教程9重要的標準庫-高級篇'} {'name': '[雪峰磁針石博客]python3快速入門教程11命令行自動化工具與pexpect'} {'name': '[雪峰磁針石博客]python3快速入門教程9重要的標準庫-基礎篇'}

BeautifulSoup的默認解析器為html.parser,處理大頁面比較吃力,為此使用lxml。解釋器html5lib的行為和瀏覽器表現類似。

最新代碼地址

https://github.com/china-testing/python-api-tesing/blob/master/python-automation-cook/ch3/blogs.py

selenium訪問'https://httpbin.org/forms/post'

用selenium訪問'https://httpbin.org/forms/post',填充內容

  • 參考答案
# 討論釘釘免費群21745728 qq群144081101 567351477 # CreateDate: 2018-10-16from selenium import webdriver import timebrowser = webdriver.Chrome() browser.get('https://httpbin.org/forms/post') custname = browser.find_element_by_name("custname") custname.clear() custname.send_keys("python測試開發")time.sleep(2) for size_element in browser.find_elements_by_name("size"): if size_element.get_attribute('value') == 'medium':size_element.click()time.sleep(2) for topping in browser.find_elements_by_name('topping'):if topping.get_attribute('value') in ['bacon', 'cheese']:topping.click()time.sleep(2) browser.find_element_by_tag_name('form').submit()

執行結果

{"args": {}, "data": "", "files": {}, "form": {"comments": "", "custemail": "", "custname": "python\u6d4b\u8bd5\u5f00\u53d1", "custtel": "", "delivery": "", "size": "medium", "topping": ["bacon", "cheese"]}, "headers": {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "max-age=0", "Connection": "close", "Content-Length": "132", "Content-Type": "application/x-www-form-urlencoded", "Host": "httpbin.org", "Origin": "https://httpbin.org", "Referer": "https://httpbin.org/forms/post", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"}, "json": null, "origin": "183.62.236.90", "url": "https://httpbin.org/post" }

轉載于:https://my.oschina.net/u/1433482/blog/2247004

總結

以上是生活随笔為你收集整理的python测试工具开发面试宝典3web抓取的全部內容,希望文章能夠幫你解決所遇到的問題。

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