www.ypnh.net > python抓取网页列表print出结果生成list

python抓取网页列表print出结果生成list

改下这个函数global demolist = []def scrape_page(page): res = requests.get(page) soup = BeautifulSoup(res.text) data = soup.select('td') info = data[0].text demolist.append(info) print demolist

"""假设title.txt中每一行为一个title"""with open("title.txt", 'r') as handle: title_list = [ln.strip() for ln in handle]

直接使用print即可: list1 = ['physics', 'chemistry', 1997, 2000];list2 = [1, 2, 3, 4, 5, 6, 7 ];print ("list1[0]: ", list1[0])print ("list2[1]: ", list2[1])

mylist = list(chr(x) for x in range(ord('A'), ord('Z')))for index, item in enumerate(mylist): print '%-5s%s' % (str(index) + ".", item)打印格式什么的是要自己控制的。比如用 % 来格式化字符串。

list1 = ['a','b','c']fmt = 'index %d value is %s'print ', '.join([fmt % (idx, val) for idx, val in enumerate(list1) ])# orprint ', '.join(map( lambda x: fmt%x, enumerate(list1) ))

直接使用print即可: list依 = ['physics', 'chemistry', 依99漆, 贰000]; list贰 = [依, 贰, 三, 四, 5, 陆, 漆 ]; print ("list依[0]: ", list依[0]) ...

for m in mlist: print m # python3:print(m)

#coding=utf-8 myList=[] for i in range(5) myList[i]=input() #每个元素都是字符串,要别的类型需要自己转换 print myList

#coding=utf-8list = [1, 2, 3, 4]print str(list)[1:len(str(list)) - 1]

应该跟IDLE有关,IDLE本身在编码方面不是很完善,LZ可以换IDLE试试

网站地图

All rights reserved Powered by www.ypnh.net

copyright ©right 2010-2021。
www.ypnh.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com