代码正在运行,但保存的网址只保存在一行而不是另一行。
from bs4 import BeautifulSoup
import urllib2
import requests
import csv
import re
page=requests.get("https://www.tutorialspoint.com/python/dictionary_values.htm")
data=BeautifulSoup(page.content)
csv1=open("123.csv","wb+")
for link in data.find_all('a'):
print(link.get('href'))
csv1.write(link.get('href'))
csv1.close()
提前致谢
答案 0 :(得分:0)
使用csv1.write
模块
csv.writer
from bs4 import BeautifulSoup
import urllib2
import requests
import csv
import re
page=requests.get("https://www.tutorialspoint.com/python/dictionary_values.htm")
data=BeautifulSoup(page.content)
csv1=open("123.csv","wb+")
csv1writer = csv.writer(csv1)
for link in data.find_all('a'):
print(link.get('href'))
csv1writer.writerow([link.get('href')])
csv1.close()