随笔分类 -  Python之爬虫2

Python之爬虫2 更多的实例 http://e-learning.51cto.com/course/12043
摘要:一、创建项目 二、更改设置(setting等) 三、编码 1 # -*- coding: utf-8 -*- 2 import scrapy 3 4 5 class RenrenSpider(scrapy.Spider): 6 name = 'renren' 7 allowed_domains = 阅读全文
posted @ 2020-06-28 17:33 udbful 阅读(160) 评论(0) 推荐(0) 编辑
摘要:CrawlSpider可用于有规则的网站,对其整站的爬取 一、创建项目 scrapy startproject wxapp cd wxapp scrapy genspider -t crawl wxapp_spider wxapp-union.com 二、更改setting.py ROBOTSTXT 阅读全文
posted @ 2020-06-24 09:48 udbful 阅读(288) 评论(0) 推荐(0) 编辑
摘要:开始参考https://www.cnblogs.com/sruzzg/p/13060159.html 一、创建scrapy爬虫工程demo scrapy startproject demo 快捷创建了一个demo新工程 二、在工程中生成一个scrapy爬虫qiushibaike 1:进入工程 cd 阅读全文
posted @ 2020-06-23 22:05 udbful 阅读(222) 评论(0) 推荐(0) 编辑
摘要:滑块验证 OpenCV+python https://www.jb51.net/article/161503.htm?tdsourcetag=s_pcqq_aiomsg python+selenium... https://www.cnblogs.com/ohahastudy/p/11493971. 阅读全文
posted @ 2020-06-22 16:53 udbful 阅读(127) 评论(0) 推荐(0) 编辑
摘要:一、简单验证码识别处理 1 """""" 2 3 4 import pytesseract 5 from PIL import Image 6 from urllib import request 7 import time 8 9 def main(): 10 # 这个url也可以通过登录页面分析 阅读全文
posted @ 2020-06-22 15:05 udbful 阅读(175) 评论(0) 推荐(0) 编辑
摘要:1、 安装tesseract OCR,即Optical Character Recognition,光学字符识别,是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程。对于图形验证码来说,它们都是一些不规则的字符,这些字符确实是由字符稍加扭曲变换得到的内容。 tesseract下载地址: 链接: 阅读全文
posted @ 2020-06-22 10:50 udbful 阅读(1116) 评论(0) 推荐(0) 编辑
摘要:1 """""" 2 3 from selenium import webdriver 4 5 driver_path = r"D:\install\chromedriver\chromedriver.exe" 6 options = webdriver.ChromeOptions() 7 opti 阅读全文
posted @ 2020-06-20 23:10 udbful 阅读(184) 评论(0) 推荐(0) 编辑
摘要:一、可以使用driver.get()方法打开多个窗口但是会覆盖,所以可以用前进后退进行操作 from selenium import webdriver import time driver_path = r"D:\install\chromedriver\chromedriver.exe" dri 阅读全文
posted @ 2020-06-20 22:49 udbful 阅读(221) 评论(0) 推荐(0) 编辑
摘要:1 """selenium操作cookie""" 2 3 4 from selenium import webdriver 5 6 driver_path = r"D:\install\chromedriver\chromedriver.exe" 7 driver = webdriver.Chrom 阅读全文
posted @ 2020-06-20 21:56 udbful 阅读(143) 评论(0) 推荐(0) 编辑
摘要:在上面的实例中,一些交互动作都是针对某个节点执行的。比如,对于输入框,我们就调用它的输入文字和清空文字方法;对于按钮,就调用它的点击方法。其实,还有另外一些操作,它们没有特定的执行对象,比如鼠标拖曳、键盘按键等,这些动作用另一种方式来执行,那就是动作链。 1 """行为链""" 2 3 from s 阅读全文
posted @ 2020-06-20 21:39 udbful 阅读(194) 评论(0) 推荐(0) 编辑
摘要:Selenium可以驱动浏览器来执行一些操作,也就是说可以让浏览器模拟执行一些动作。比较常见的用法有:输入文字时用send_keys()方法,清空文字时用clear()方法,点击按钮时用click()方法。示例如下: 1 """selenium操作表单元素""" 2 # 常见的表单元素: 3 # i 阅读全文
posted @ 2020-06-20 00:24 udbful 阅读(329) 评论(0) 推荐(0) 编辑
摘要:webdriver 提供了一系列的元素定位方法,常用的有以下几种: find_element_by_id() # 通过元素ID定位 find_element_by_name() # 通过元素Name定位 find_element_by_class_name() # 通过类名定位 find_eleme 阅读全文
posted @ 2020-06-19 21:46 udbful 阅读(199) 评论(0) 推荐(0) 编辑
摘要:selenium简介 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题。 selenium本质是通过驱动浏览器,完全模拟浏览器的操作,比如跳转、输入、点击、下拉等,来拿到网页渲染之后的结果,可支持多种浏览器 安装sele 阅读全文
posted @ 2020-06-17 22:39 udbful 阅读(256) 评论(0) 推荐(0) 编辑
摘要:1 """写入csv文件""" 2 3 4 import csv 5 6 # 方法一: 7 def write_csv_demo1(): 8 headers = ['username', 'age', 'height'] 9 values = [ 10 ('张三', 18, 180), 11 ('李 阅读全文
posted @ 2020-06-15 22:22 udbful 阅读(190) 评论(0) 推荐(0) 编辑
摘要:1 """读取csv文件""" 2 3 4 import csv 5 6 def readcsv_demo1(): 7 """采用列表形式,下标操作""" 8 with open('csvwriter.csv', 'r') as fp: 9 # reader是一个迭代器 10 reader = cs 阅读全文
posted @ 2020-06-15 22:14 udbful 阅读(178) 评论(0) 推荐(0) 编辑
摘要:1 """json字符串到Python对象""" 2 3 4 import json 5 6 json_str = '[{"username": "张三", "age": 18, "country": "china"}, {"username": "lisi", "age": 20, "countr 阅读全文
posted @ 2020-06-15 22:01 udbful 阅读(739) 评论(0) 推荐(0) 编辑
摘要:1 """ptyhon对象转json字符串""" 2 3 4 import json 5 6 persons = [ 7 {'username': '张三', 'age': 18, 'country': 'china'}, 8 {'username': 'lisi', 'age': 20, 'cou 阅读全文
posted @ 2020-06-15 21:59 udbful 阅读(108) 评论(0) 推荐(0) 编辑
摘要:1 """古诗文网爬虫""" 2 3 4 import re 5 import requests 6 7 def parse_page(url): 8 headers = { 9 'User-Agent': 'Mozilla/5.0', 10 } 11 12 response = requests. 阅读全文
posted @ 2020-06-14 23:47 udbful 阅读(246) 评论(0) 推荐(0) 编辑
摘要:一、常用案例 1 """正则表达式小案例""" 2 3 import re 4 5 # 1、验证手机号码 6 text = "13979391000" 7 ret = re.match('1[34578]\d{9}', text) 8 print(ret.group()) # 2、验证邮箱 text 阅读全文
posted @ 2020-06-12 23:19 udbful 阅读(238) 评论(0) 推荐(0) 编辑
摘要:1 """中国天气网爬虫""" 2 3 import requests 4 from bs4 import BeautifulSoup 5 from pyecharts import Bar 6 7 8 HEADERS = { 9 'User-Agent': 'Mozilla/5.0' 10 } 1 阅读全文
posted @ 2020-06-12 17:32 udbful 阅读(323) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示