我爬虫的目标网址是http://jobs.monster.com/search/software_5
想要保存这个网站上每一条工作的标题、链接、公司和发布时间
我自己检查的时候用sites = hxs.select('//div')获取所有的div
结果发现本来只能得到一条工作的信息
例如:每个工作里都该有个div class=jobTitle,但是在数据里只能找到一个这样的div
这个网站刚刚改版,之前都还能顺利获取数据,请有经验的大神指点我一个解决方案。
我爬虫的目标网址是http://jobs.monster.com/search/software_5
想要保存这个网站上每一条工作的标题、链接、公司和发布时间
我自己检查的时候用sites = hxs.select('//div')获取所有的div
结果发现本来只能得到一条工作的信息
例如:每个工作里都该有个div class=jobTitle,但是在数据里只能找到一个这样的div
这个网站刚刚改版,之前都还能顺利获取数据,请有经验的大神指点我一个解决方案。
我也是遇到这样的情况,我直接抓ajax的url,不知道为什么只抓到其中一条,shell的时候可以抓到所有,而且抓到的一条也没有规律。你能帮我看一下吗
import scrapy
import json
import codecs
from scrapy.http import Request
from shanbaySpider.shanbayitems import ShanbayItem
class shanbaySpider(scrapy.Spider):
name = 'shanbay'
allow_domains = ["www.shanbay.com"]
start_urls = [
'https://www.shanbay.com/api/v1/forum/11077/thread/?page=1&_=1519905668004']
custom_settings = {
"DEFAULT_REQUEST_HEADERS": {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
'Connection': 'keep-alive',
'Cookie': 'csrftoken=gFndgohTbX9gLqzHgdWqzRcO3pA1YyNC; __utmc=183787513; __utmz=183787513.1519280609.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=183787513.2023983996.1519280609.1519565215.1519904654.7; __utmb=183787513.1.10.1519904654',
'Host': 'www.shanbay.com',
'Referer': 'https://www.shanbay.com/forum/daily-translation/',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
}
def parse(self, response):
res = json.loads(response.body.decode('gbk').encode('utf-8'))
threads = res['data']['threads']
threadItem = []
for dict in threads:
threadItem = ShanbayItem()
threadItem['title'] = dict['title']
threadItem['author'] = dict['author']
threadItem['topic_post_time'] = dict['topic_post_time']
yield threadItem
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
已解决
数据都在js里面,直接通过response.body用正则表达式获取了js里面的数据。方法不大好,有相同问题的同学可以去研究Python-webkit。