随笔分类 - 爬虫
学习练习爬虫
摘要:import emoji #去掉表情等特殊字符 jieshao="包括表情的字符串" jieshao=emoji.demojize(jieshao) def filter_emoji(self,desstr,restr='[emoji]'): ''' 过滤表情 ''' try: co = re.co
阅读全文
摘要:''' 三种等待方法: 1.强制等待sleep(xx) 强制等待,不管你浏览器是否加载完了,程序都得等待,时间一到,继续执行下面的代码,作为调试很有用,有时候也可以在代码里这样等待,不过不建议总用这种等待方式,太死板,严重影响程序执行速度。 2.隐性等待implicitly_wait(xx) 隐形等
阅读全文
摘要:from selenium.webdriver import Remote from selenium.webdriver.chrome import options from selenium.common.exceptions import InvalidArgumentException im
阅读全文
摘要:import pymysql,itertools connect = pymysql.connect( user = 'm', password = '0', db = 'x', host = 'r', port = 3306, charset = 'utf8' ) con =connect.cur
阅读全文
摘要:if isinstance(item,MmzItem): data = {'xinxi':item['xinxi']} xinxia = data['xinxi'] print(len(xinxia),type(xinxia)) #print("ffffffffffffff",xinxi[0],xi
阅读全文
摘要:url="https://www.liepin.com/campus/" import requests from bs4 import BeautifulSoup rr=requests.get(url) soup =BeautifulSoup(rr.text, "lxml") for itema
阅读全文
摘要:url="https://www.liepin.com/job/1932123793.shtml" import requests from bs4 import BeautifulSoup rr=requests.get(url) soup =BeautifulSoup(rr.text, "lxm
阅读全文
摘要:今天写爬虫,遇到一个坑,提示[scrapy.core.scraper] ERROR: Spider must return request, item, or None, got 'Tag' in <GET https://www. 其实原因很意外,我在代码中使用了item,同时scrapy又用it
阅读全文
摘要:def __init__(self, *args, **kwargs): super(MmzzSpider, self).__init__(*args, **kwargs) # 这里是关键 self.count=0 def parse_item(self, response): soup =Beau
阅读全文
摘要:from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selen
阅读全文
摘要:python3爬虫:爬虫进阶之ajax数据爬取发布时间: 2019-02-06 19:21:14动态网页数据抓取什么是AJAX:AJAX(Asynchronouse JavaScript And XML)异步JavaScript和XML。通过在后台与服务器进行少量数据交换,Ajax 可以使网页实现异
阅读全文
摘要:1.python -m pip install --upgrade pip(升级PIP) 2.pip install wheel 3.pip install lxml 4.pip install twisted 5.pip install pywin32 6.pip install srapy
阅读全文
摘要:import os def file_name(file_dir): for root, dirs, files in os.walk(file_dir): print(root) #当前目录路径 print(dirs) #当前路径下所有子目录 print(files) #当前路径下所有非目录子文件
阅读全文
摘要:https://images.weserv.nl/?url=
阅读全文
摘要:自定义file_path()函数,即可以原有图像文件名为名来保存,并分类保存 def file_path(self, request, response=None, info=None): image_guid = request.url.split('/')[-2]+"/"+request.url
阅读全文
摘要:运行scrapy时出错这个错误:Max retries exceeded with url解决方法: img1=requests.get(url=aa,headers=header1,timeout=5,verify=False)爬虫能运行了,但还是报错,但不影响使用
阅读全文
摘要:https://tools.zzzmode.com/mytools/charles/ https://www.charlesproxy.com/download/
阅读全文
摘要:1.建立爬虫项目(结果形成与名称相同的文件夹) scrapy startproject <爬虫项目名称> (下面的所有操作都进入下一级文件进行操作) 2建立一个爬虫 scrapy genspider [- t 模板名称] <爬虫名称> < 爬虫爬取的域名> 3.运行一个爬虫scrapy craw <
阅读全文
摘要:在PY文件中: from scrapy.selector import Selectorfrom scrapy.http import HtmlResponse url="https://m.mm131.net/" r=requests.get(url) r.encoding='gbk' #根据情况
阅读全文
摘要:1。在middlewares中添加自己的新类: class Mylei(object): def process_request(self,request,spider): referer=request.url if referer: request.headers["referer"] = re
阅读全文