V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wudaown
V2EX  ›  Python

python 爬虫(学校选科)

  •  1
     
  •   wudaown · 2016-09-01 17:09:42 +08:00 · 3465 次点击
    这是一个创建于 2766 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://wish.wis.ntu.edu.sg/webexe/owa/aus_schedule.main

    现有学校某个网址,没有地方让我 post 数据。

    用 chrome 观察了 network 也没有突破的地方。有一个 request header

    不过在 urllib.request 和 urllib.parse.urlencode()里试过了。没有返回任何结果。

    希望大家帮忙看看怎么爬去这个页面后面返回的所有数据。

    谢谢大家了

    19 条回复    2016-09-02 10:34:43 +08:00
    tumbzzc
        1
    tumbzzc  
       2016-09-01 17:21:51 +08:00
    没说清楚具体要什么
    waterhhk
        2
    waterhhk  
       2016-09-01 17:22:10 +08:00
    学校内网?
    wudaown
        3
    wudaown  
    OP
       2016-09-01 17:26:07 +08:00
    @waterhhk 外面上不去么?
    Shazoo
        4
    Shazoo  
       2016-09-01 17:32:37 +08:00
    有啊。
    导成 curl 的命令给你:
    curl 'https://wish.wis.ntu.edu.sg/webexe/owa/AUS_SCHEDULE.main_display1' -H 'Pragma: no-cache' -H 'Origin: https://wish.wis.ntu.edu.sg' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: https://wish.wis.ntu.edu.sg/webexe/owa/aus_schedule.main' -H 'Connection: keep-alive' --data 'acadsem=2016%3B1&r_course_yr=ACC%3BGA%3B1%3BF&r_subj_code=Enter+Keywords+or+Course+Code&r_search_type=F&boption=CLoad&acadsem=2016%3B1&staff_access=false' --compressed
    wudaown
        5
    wudaown  
    OP
       2016-09-01 17:35:39 +08:00
    @Shazoo 请问是怎么做到的?能稍微解释一下吗?另外 python 是实现能稍微说一下嘛?非常感谢
    UnisandK
        6
    UnisandK  
       2016-09-01 17:37:58 +08:00
    你是不是跳新窗口 network 没有东西。。刷新一下重新发送数据就有了
    挺简单一个 post 连防爬虫都没做。。

    wudaown
        7
    wudaown  
    OP
       2016-09-01 17:38:35 +08:00
    APPEND
    不知道为什么不能 append 了

    具体就是这里点了 Load Class Schedule



    出现下面的这个页面的数据



    就是 @Shazoo 做到的
    laoyuan
        8
    laoyuan  
       2016-09-01 17:39:43 +08:00
    这种弹出新标签页的,在新标签页点开发者工具然后刷新下,就能看到请求了。
    wudaown
        9
    wudaown  
    OP
       2016-09-01 17:41:50 +08:00
    @laoyuan
    @UnisandK
    @Shazoo 我在新的窗口确实看到看到请求了,不过没有地方让我 post 啊,没有看到接口
    laoyuan
        10
    laoyuan  
       2016-09-01 17:43:30 +08:00
    点 Headers 看发送的数据,最下面 Form data
    laoyuan
        11
    laoyuan  
       2016-09-01 17:45:16 +08:00
    每年开学都要搞搞这一套,我上午还抓山大的课表好看空教室,结果选课系统的“本学期课程查询” 404 了,火大
    wudaown
        12
    wudaown  
    OP
       2016-09-01 17:45:33 +08:00
    @laoyuan 看到了,所以不用类似 google 搜索这样的接口,直接一起 post 就可以?
    wudaown
        13
    wudaown  
    OP
       2016-09-01 17:47:51 +08:00
    @laoyuan 然而还是不明白如何 python 实现
    UnisandK
        14
    UnisandK  
       2016-09-01 17:49:56 +08:00
    这不就是接口。。


    这是 Pow 自动生成的 Python 实现
    ```python
    # Install the Python Requests library:
    # `pip install requests`

    import requests


    def send_request():
    # Request
    # POST https://wish.wis.ntu.edu.sg/webexe/owa/AUS_SCHEDULE.main_display1

    try:
    response = requests.post(
    url="https://wish.wis.ntu.edu.sg/webexe/owa/AUS_SCHEDULE.main_display1",
    headers={
    "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
    },
    data={
    "boption": "CLoad",
    "r_search_type": "F",
    "acadsem": "2016;1,2016;1",
    "r_course_yr": "ACC;GA;1;F",
    "r_subj_code": "Enter Keywords or Course Code",
    "staff_access": "false",
    },
    )
    print('Response HTTP Status Code: {status_code}'.format(
    status_code=response.status_code))
    print('Response HTTP Response Body: {content}'.format(
    content=response.content))
    except requests.exceptions.RequestException:
    print('HTTP Request failed')



    ```
    wudaown
        15
    wudaown  
    OP
       2016-09-01 17:52:16 +08:00
    @UnisandK pow 是什么东西,看起来好神奇
    UnisandK
        16
    UnisandK  
       2016-09-01 17:53:47 +08:00
    @wudaown HTTP 调试工具, 6L 图里那个
    wudaown
        17
    wudaown  
    OP
       2016-09-01 17:56:57 +08:00
    @UnisandK 谢谢,估计够我研究一段时间了
    Shazoo
        18
    Shazoo  
       2016-09-01 19:13:41 +08:00
    额, 8 楼说的估计是你这边的根源问题。

    找 post 指令啥的,都很简单啦。一看就懂。
    pekingzcc
        19
    pekingzcc  
       2016-09-02 10:34:43 +08:00
    楼上上说的因该是 paw 吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2670 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:15 · PVG 23:15 · LAX 08:15 · JFK 11:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.