Python学习
jason3586596
这个作者很懒,什么都没留下…
展开
-
lxml结合xpath注意事项
1.使用Xpath语法,应该使用Element.xpath方法,来执行xpath选择,示例代码如下: trs = html.xpath("//tr[position()>2]") xpath函数返回的永远是一个列表 2.获取某个标签的属性: href = html.xpath("//a/@href") 3.获取文本 , 通过xpath下的text()函数: address = tr.xpath("./td[4]/text()")[0] 4.在某个标签下使用xpath函数 , 获取其子孙函数, 应原创 2020-07-19 13:48:47 · 231 阅读 · 0 评论 -
网络爬虫-课时21剖析分页信息
网络学习笔记 import requests res = requests.get('http://api.roll.news.sina.com.cn/zt_list?channel=news&cat_1=gnxw&cat_2==gdxw1||=gatxw||=zs-pl||=mtjj&level==1||=2&show_ext=1&show_all=1...原创 2018-08-28 22:17:25 · 152 阅读 · 0 评论 -
转换为首字母缩写
str1 = input("请输入英文单词:") str2 = str1.upper() list1 = str2.split() for word in list1: print(word[0], end = '') 注意最后加入end = '',否则自动换行原创 2018-08-28 22:15:49 · 1028 阅读 · 0 评论 -
网络爬虫-课时9抓取新闻内文页面
import requests from bs4 import BeautifulSoup res = requests.get('http://news.sina.com.cn/c/nd/2016-08-20/doc-ifxvctcc8121090.shtml') res.encoding = 'utf-8' print(res.text) soup = BeautifulSoup(res.te...原创 2018-06-30 10:18:52 · 386 阅读 · 0 评论 -
网络爬虫-课时5 用BeautifulSoup 剖析网页元素
打开运行,输入jupyter booknew(新建) python3import requestsres = requests.get('http://news.sina.com.cn/')res.encoding = 'utf-8'#print (res.text)from bs4 import BeautifulSouphtml_sample = ' \<html> \ <b...原创 2018-06-28 21:14:40 · 198 阅读 · 0 评论 -
网络爬虫-课时15抓取新闻评论数
import requests commments = requests.get('http://comment5.news.sina.com.cn/page/info?version=1&format=js&channel=gn&newsid=comos-fxvctcc8121090&group=&compress=0&ie=utf-8&o...原创 2018-07-01 11:49:09 · 478 阅读 · 0 评论 -
网络爬虫-课时18信息抽取函式
来自网络学习笔记原创 2018-07-01 11:46:13 · 205 阅读 · 0 评论 -
Python Counter函数
>>> c = Counter() # 创建一个新的空counter >>> c = Counter('abcasdf') # 一个迭代对象生成的counter >>> c = Counter({'red': 4, 'yello': 2}) # 一个...转载 2018-04-25 08:25:27 · 3849 阅读 · 0 评论