【发布时间】:2017-02-15 13:13:57
【问题描述】:
我有一个名为“df”的 csv,有 1 列。我有一个标题和 10 个网址。
Col
"http://www.cnn.com"
"http://www.fark.com"
etc
etc
这是我的错误代码
import bs4 as bs
df_link = pd.read_csv('df.csv')
for link in df_link:
x = urllib2.urlopen(link[0])
new = x.read()
# Code does not even get past here as far as I checked
soup = bs.BeautifulSoup(new,"lxml")
for text in soup.find_all('a',href = True):
text.append((text.get('href')))
我收到一个错误提示
ValueError: unknown url type: C
我也得到了这个错误的其他变体,比如
问题是,它甚至没有过去
x = urllib2.urlopen(link[0])
另一方面;这是工作代码...
url = "http://www.cnn.com"
x = urllib2.urlopen(url)
new = x.read()
soup = bs.BeautifulSoup(new,"lxml")
for link in soup.find_all('a',href = True):
links.append((link.get('href')))
【问题讨论】:
标签: python beautifulsoup urllib2