Python + selenium + phantomjs 求助,爬一个网站的信息 - V2EX
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
doulmi
V2EX    Python

Python + selenium + phantomjs 求助,爬一个网站的信息

  •  
  •   doulmi 2017-02-26 21:53:43 +08:00 3110 次点击
    这是一个创建于 3163 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近公司要求爬下 http://www.kuajingjishi.com/Purchase/SearchPurchase#pageIndex=10 页面的采购信息,本以为会是比较简单的事情,结果每次爬下来都是第一页的内容

    from selenium import webdriver driver = webdriver.PhantomJS() driver.get('http://www.kuajingjishi.com/Purchase/SearchPurchase#pageIndex=2') result = driver.find_element_by_tag_name('table') print(result.get_attribute('innerHTML')) 

    求助求助~

    6 条回复    2017-02-27 10:32:01 +08:00
    aploium
        1
    aploium  
       2017-02-26 22:02:57 +08:00
    ```python
    import requests

    data = {
    'X-Requested-With': 'XMLHttpRequest'
    }

    for i in range(1,10):
    url='http://www.kuajingjishi.com/Purchase/SearchPurchase?pageIndex={page}'.format(page=i)
    r=requests.post(url, data=data)
    print(r.text)
    ```
    aploium
        2
    aploium  
       2017-02-26 22:17:25 +08:00
    它是用 ajax 加载的, 浏览器里用 F12, 选 network 那个 tab, 手动点一下那几个页面, 能看到它发出去的请求, 然后自己一模一样发好了
    这个站还没对请求进行验证......orz

    至于为什么 selenium 弄不到......天知道:)

    tips: 在请求上右键->copy->copy as cURL 然后在这个网站能直接转换为 requests 格式 https://curl.trillworks.com/
    doulmi
        3
    doulmi  
    OP
       2017-02-26 23:39:58 +08:00
    @aploium 谢谢你!
    mingyun
        4
    mingyun  
       2017-02-26 23:44:20 +08:00
    @aploium 这个网站好
    MyFaith
        5
    MyFaith  
       2017-02-27 08:38:03 +08:00
    pageIndex:9
    POST 的时候把这个参数加上就好了,只是一个 AJAX 加载
    cranelee13
        6
    cranelee13  
       2017-02-27 10:32:01 +08:00
    python 爬虫只有到完全没办法,反爬实在厉害才用 selenium + phantomjs ,绝大多数情况用 requests 应付就行。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2444 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 05:16 PVG 13:16 LAX 22:16 JFK 01:16
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86