python - 爬虫(淘宝)无输出
迷茫
迷茫 2017-04-17 17:44:28
[Python讨论组]
import requests
from bs4 import BeautifulSoup

res=requests.get('https://s.taobao.com/search?
initiative_id=tbindexz_20160515&ie=utf8&spm=a21bo.50862.201856-taobao-item.2&sourceId=tb.index&search_type=item&ssid=s5-e&commend=all&imgfile=&q=python%E4%B9%A6%E7%B1%8D&suggest=0_5&_input_charset=utf-8&wq=python&suggest_query=python&source=suggest')

soup=BeautifulSoup(res.text,'lxml')

for item in soup.select('.item'):
    print item.select('strong')

为什么这个爬虫我用pycharm跑总是Process finished with exit code 0

没法得到输出,但程序也没什么错?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(1)
大家讲道理
import requests
import re
import json


res = requests.get('https://s.taobao.com/search?initiative_id=tbindexz_20160515&ie=utf8&spm=a21bo.50862.201856-taobao'
                   '-item.2&sourceId=tb.index&search_type=item&ssid=s5-e&commend=all&imgfile=&q=python%E4%B9%A6%E7%B1'
                   '%8D&suggest=0_5&_input_charset=utf-8&wq=python&suggest_query=python&source=suggest')
rs = re.search(r'g_page_config = (.*?);\n', res.text)
g_page_config = json.loads(rs.group(1))
items = g_page_config['mods']['itemlist']['data']['auctions']
for item in items:
    print('-' * 100)
    print(item['raw_title'])
    print(item['view_price'])

可以用这种方法取出数据,不过感觉怪怪的就是了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号