用urllib和BeautifulSoup获取维基百科词条信息
来源:互联网 发布:淘宝网上的女装 编辑:程序博客网 时间:2024/06/06 03:07
notes:由图可以看到Request Method是GET,使用postman注意方法选择。
简单的例子:用urllib和BeautifulSoup获取维基百科词条信息
from urllib.request import urlopenfrom bs4 import BeautifulSoupimport re#请求url并把结果用utf-8编码resp=urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")#使用BeautifulSoup去解析soup=BeautifulSoup(resp,"html.parser")#获取所有易/wiki/开头的a标签的href属性listUrls=soup.findAll("a",href=re.compile("^/wiki"))#输出所有的词条名称和urlfor url in listUrls: #过滤以.jpg或者.JPG结尾的url if not re.search("\.(jpg|JPG)$",url["href"]): # print(url["href"]) #string只能获取一个 get_text()获取标签下所有文字 print(url.get_text(),"<---->","https://en.wikipedia.org"+url["href"])
阅读全文
0 0
- 用urllib和BeautifulSoup获取维基百科词条信息
- 利用urllib和BeautifulSoup爬取维基百科的词条
- 用urllib、BeautifulSoup抓取糗事百科段子
- 获取维基百科主页所有词条及链接
- 使用urllib和BeautifulSoup怕取维基百科的数据
- 把获取的维基百科主页词条及链接存入mysql数据库
- python爬虫入门:1--爬取维基百科词条信息
- urllib/urllib2和BeautifulSoup爬虫学习
- HDkiwi 百科词条缩略图
- Base64 百科词条
- 百度百科词条和优酷打开显示乱码
- python urllib* 获取网页信息
- Python爬取百度百科,BeautifulSoup提取关键信息
- 使用BeautifulSoup模块获取糗事百科上的笑话
- Python使用urllib库和BeautifulSoup库爬虫总结
- Python开发爬虫爬取百度百科词条信息(源码下载)
- 百度百科 > 浏览词条 lua
- python爬虫-百度百科词条
- Zookeeper系列(一)
- Fragment详解系列一什么是Fragment
- Struts2整合Spring无法获取到网页传过来的参数
- Linux下gerp命令-----C代码实现
- java语言调用摄像头 (不是照相机)
- 用urllib和BeautifulSoup获取维基百科词条信息
- 机器学习----混合高斯模型
- golang interface理解
- 有哪些类加载器?解释什么是双亲委派模型,为什么使用双亲委派模型,如何自定义类加载器?什么时候应该自定义类加载器?
- python+selenium
- 需求推送变革!陈小平教授深度剖析机器人因何由精确性转向灵巧性
- python里使用map()函数
- ssh: connect to host master port 22: Connection refused
- numpy巩固