瑞客论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1698|回复: 13

[经验求助] 求各位大神帮解决,一个小小的爬虫问题

[复制链接]

1

主题

30

帖子

360

积分

中级会员

Rank: 3Rank: 3

威望
72
贡献
72
热心值
0
金币
216
注册时间
2021-8-29
发表于 2021-8-30 20:56 | 显示全部楼层 |阅读模式
10金币
http://www.yinsuwang.com/exam/catalogue.html?id=2
想爬免费的题库,但是获取不到

图片中的数据就是我想要的,但是python,总是无法获得

import requests
import json

headers ={"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection":"keep-alive",
"Content-Length": "24",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Cookie": "PHPSESSID=6e7e1dl6h5lu8sd28lio5rbge2",
"Host": "www.yinsuwang.com",
"Origin": "http://www.yinsuwang.com",
"Referer": "http://www.yinsuwang.com/exam/taste.html?id=2&exam_id=14375",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"}
data = "{'key':'value'}"

url = "http://www.yinsuwang.com/api/taste/get.json"


response = requests.post(url,data=data,headers=headers)

print(response.text)


123.jpg

最佳答案

查看完整内容

替换下cookie,访问exam_id=14441,是可以访问的,可能14408本来就是登录才能访问的资源 import requests import json headers ={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Cookie": "xxxxxxxxxxxxxxxx", "Host": "www.yinsuwang.com", "Origin": "http://www.yinsuwang.com", "Referer": "http://www.yinsuwang.com/exam/taste.html?id=2&exam_id=14441", "User-Agent": "Mozilla/5 ...
回复

使用道具 举报

4

主题

943

帖子

8988

积分

论坛元老

Rank: 8Rank: 8

威望
3635
贡献
3955
热心值
0
金币
1398
注册时间
2020-3-9
发表于 2021-8-30 20:56 | 显示全部楼层
大连小熊 发表于 2021-8-31 07:39
我加参数了,还是不行,能不能用python给我解一下,js我不会用

import requests

替换下cookie,访问exam_id=14441,是可以访问的,可能14408本来就是登录才能访问的资源

import requests
import json

headers ={
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Cookie": "xxxxxxxxxxxxxxxx",
"Host": "www.yinsuwang.com",
"Origin": "http://www.yinsuwang.com",
"Referer": "http://www.yinsuwang.com/exam/taste.html?id=2&exam_id=14441",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"}
data = {'level_id':'2','exam_id':'14441'}
url = "http://www.yinsuwang.com/api/taste/get.json"
response = requests.post(url,data=data,headers=headers).json()
print(response)
回复

使用道具 举报

24

主题

534

帖子

8229

积分

论坛元老

Rank: 8Rank: 8

威望
1636
贡献
1893
热心值
4
金币
4696
注册时间
2020-2-11

一年荣誉奖章活跃会员最佳新人

发表于 2021-8-30 23:44 | 显示全部楼层
忘了传参数了吧
回复

使用道具 举报

2

主题

1451

帖子

5343

积分

论坛元老

Rank: 8Rank: 8

威望
2329
贡献
2578
热心值
0
金币
436
注册时间
2020-4-14

活跃会员灌水之王一年荣誉奖章

发表于 2021-8-30 23:49 | 显示全部楼层
加了检测的
回复

使用道具 举报

24

主题

534

帖子

8229

积分

论坛元老

Rank: 8Rank: 8

威望
1636
贡献
1893
热心值
4
金币
4696
注册时间
2020-2-11

一年荣誉奖章活跃会员最佳新人

发表于 2021-8-30 23:54 | 显示全部楼层
本帖最后由 q2419068625 于 2021-8-30 23:56 编辑

const superagent = require('superagent');
const url = 'http://www.yinsuwang.com/api/taste/get.json'

const header =  {
  "Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection":"keep-alive",
"Content-Length": "24",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Cookie": "PHPSESSID=pahq734f3j4fnu3ndopgdj3p4o",
"Host": "www.yinsuwang.com",
"Origin": "http://www.yinsuwang.com",
"Referer": "http://www.yinsuwang.com/exam/taste.html?id=2&exam_id=14375",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"
}

function request(url) {
  superagent.post(url).set(header).send({
    level_id: 2,
    exam_id: 14408
  }).end((err, res) => {
    if (err) return
    const papers = JSON.parse(res.text).data.paper
    papers.forEach(v => {
      if (v.annex) {
        console.log(`http://www.yinsuwang.com${v.annex}`);
      }
    });

  })
}
request(url)


Node.js 版本,





微信截图_20210830235333.png
回复

使用道具 举报

24

主题

534

帖子

8229

积分

论坛元老

Rank: 8Rank: 8

威望
1636
贡献
1893
热心值
4
金币
4696
注册时间
2020-2-11

一年荣誉奖章活跃会员最佳新人

发表于 2021-8-31 00:00 | 显示全部楼层
这个网站太不稳定了,有时候请求都发不了, 垃圾网站
回复

使用道具 举报

24

主题

534

帖子

8229

积分

论坛元老

Rank: 8Rank: 8

威望
1636
贡献
1893
热心值
4
金币
4696
注册时间
2020-2-11

一年荣誉奖章活跃会员最佳新人

发表于 2021-8-31 00:02 | 显示全部楼层
回复

使用道具 举报

1

主题

30

帖子

360

积分

中级会员

Rank: 3Rank: 3

威望
72
贡献
72
热心值
0
金币
216
注册时间
2021-8-29
 楼主| 发表于 2021-8-31 07:28 | 显示全部楼层
python怎么就死活爬不出来呢
回复

使用道具 举报

1

主题

30

帖子

360

积分

中级会员

Rank: 3Rank: 3

威望
72
贡献
72
热心值
0
金币
216
注册时间
2021-8-29
 楼主| 发表于 2021-8-31 07:39 | 显示全部楼层
我加参数了,还是不行,能不能用python给我解一下,js我不会用

import requests
import json

headers ={
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Cookie": "PHPSESSID=6e7e1dl6h5lu8sd28lio5rbge2",
"Host": "www.yinsuwang.com",
"Origin": "http://www.yinsuwang.com",
"Referer": "http://www.yinsuwang.com/exam/taste.html?id=2&exam_id=14375",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"}
data = "{'level_id':'2','exam_id'='14408'}"
data_json = json.dumps(data)
url = "http://www.yinsuwang.com/api/taste/get.json"


response = requests.post(url,data=data_json,headers=headers)

change = response.json()
new_req = json.dumps(change,ensure_ascii=False)

print(new_req)
回复

使用道具 举报

1

主题

30

帖子

360

积分

中级会员

Rank: 3Rank: 3

威望
72
贡献
72
热心值
0
金币
216
注册时间
2021-8-29
 楼主| 发表于 2021-8-31 14:19 | 显示全部楼层
wynanwong 发表于 2021-8-31 14:13
替换下cookie,访问exam_id=14441,是可以访问的,可能14408本来就是登录才能访问的资源

import reque ...

还是不行,返回{'status': False, 'code': None, 'error': '创建失败,请登录后操作'}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|瑞客论坛 |网站地图

GMT+8, 2024-5-2 01:58

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表