search

Home  >  Q&A  >  body text

用Python成功抓取了url和文章标题,写入csv后打开只有一条数据,是哪里出错了呢?

PHP中文网PHP中文网2811 days ago255

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 09:35:10

    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())

    reply
    0
  • Cancelreply