spider蜘蛛类的参数传递,重写staart_url方法。
能复制的尽量别手写,大小写的区分可以调试一年。
划重点上干货
1 模块不存在
排查路径,反复报错‘模块’不存在的。文件夹添加init文件。然后将文件夹拖到python37目录中,因为这个路径是添加到了环境变量中的,可以通过import sys,sys.path查看,python中import 搜索模块会优先从sys.path中查找,至于添加sys.path.append()太坑了,只是临时添加路径。所以有兴趣的童鞋请自行爬坑
2.`import scrapy
from myweb.myfirstpjt.myfirstpjt.items import MyfirstpjtItem
class WeisuenSpider(scrapy.Spider):
name = ‘weisuen’
start_urls = [
'http://slide.news.com.cn/k/slide_8_193_45192.html #p=1',
]
def __init__(self,myurl=None,*args,**kwargs):
super(WeisuenSpider,self).__init__(*args,**kwargs)
print("要爬取的网址为:%s"%myurl)
def parse(self, response):
item=MyfirstpjtItem()
item['urlname']=response.xpath("/html/head/title/text()")
print("以下将显示爬取的网址的标题")
print(item['urlnam