Heim  >  Fragen und Antworten  >  Hauptteil

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

PHP中文网PHP中文网2741 Tage vor215

Antworte allen(1)Ich werde antworten

  • 天蓬老师

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

    你的csvrow1和csvrow2放错位置了,你放在循环内部,每次循环都直接被初始化为空列表了

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

    Antwort
    0
  • StornierenAntwort