【发布时间】:2015-12-30 02:06:13
【问题描述】:
我需要做些什么来防止错误:AttributeError: 'list' object has no attribute 'split lines' 在这里发生?如何将我拥有的列表转换为可以具有 splitlines 属性的表单?
import requests
import re
from bs4 import BeautifulSoup
import csv
#Read csv
with open ("gyms4.csv") as file:
reader = csv.reader(file)
csvfilelist = [row[0] for row in reader]
print csvfilelist
#Get data from each url
def get_page_data():
for page_data in csvfilelist.splitlines():
r = requests.get(page_data.strip())
soup = BeautifulSoup(r.text, 'html.parser')
yield soup
【问题讨论】:
-
您已经有一个列表。为什么你认为你需要拆分它?
-
list没有splitlines,str有。
标签: python csv web-scraping beautifulsoup