用Python成功抓取了url和文章标题,写入csv后打开只有一条数据,是哪里出错了呢?
PHP中文网
PHP中文网 2017-04-18 09:33:10
0
1
257
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
Peter_Zhu

Your csvrow1 and csvrow2 are placed in the wrong place. You put them inside the loop, and each loop is directly initialized to an empty list

csvrow1=[]
csvrow2=[]
for links in get_data('http://finance.qq.com/gdyw.htm'):
        csvrow1.append('http://finance.qq.com/'+links.get('href'))
    for title in get_data('http://finance.qq.com/gdyw.htm'):
        csvrow2.append(title.get_text())
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template