无法读取带有URL的csv以在python中将其报废

时间:2019-03-12 14:22:38

标签: python web-scraping

我是python的新手,所以我尝试了以下Visual Studio和Windows 7

import csv
from bs4 import BeautifulSoup 
import requests 

contents = []
with open('websupplies.csv','r') as csvf: # Open file in read mode
   urls = csv.reader(csvf)

   for url in urls:
      contents.append(url) # Add each url to list contents


for url in contents:  # Parse through each url in the list.
   page = requests.get(url).content
   soup = BeautifulSoup(page, "html.parser")

   price = soup.find('span', attrs={'itemprop':'price'})
   availability = soup.find('div', attrs={'class':'product-availability'})

但是我得到了-未找到..'['a url']'

的连接适配器

为什么?

csv的结构如下

https://www.websupplies.gr/epeksergastis-intel-core-i5-8400-9mb-2-80ghz-bx80684i58400
https://www.websupplies.gr/epeksergastis-intel-celeron-g3930-2mb-2-90ghz-bx80677g3930
https://www.websupplies.gr/epeksergastis-amd-a6-9500-bristol-ridge-dual-core-3-5ghz-socket-am4-65w-ad9500agabbox

他们最后没有分号

1 个答案:

答案 0 :(得分:1)

this问题中,它说请求需要http方案,也许这是问题所在吗?当您从文件中读取行时,还必须删除/ n