单纯地练习一下xpath

 import requests
from lxml import etree def get_url(url):
html = requests.get(url)
return html.text def parse_html(html):
informations = []
html_element = etree.HTML(html)
ul = html_element.xpath('//ul[@class="lists"]')[0]
for li in ul:
href = li.xpath('.//li[@class="poster"]/a/@href')
title = li.xpath('normalize-space(.//li[@class="stitle"]/a/@title)') #normalize-space 去掉换行符
mark = li.xpath('.//span[@class="subject-rate"]/text()')
actor = li.xpath('@data-actors')
director = li.xpath('@data-director')
# print(etree.tostring(uls, encoding='utf-8').decode('utf-8'))
information = {
'href': href,
'title': title,
'mark': mark,
'actors': actor,
'director': director
}
informations.append(information) print(informations) def main():
url = 'https://movie.douban.com/cinema/nowplaying/beijing/'
html = get_url(url)
parse_html(html) if __name__ == '__main__':
main()

爬虫_豆瓣全部正在热映电影 (xpath)的更多相关文章

  1. python爬虫——爬取淘票票正在热映电影

    今天正好学习了一下python的爬虫,觉得收获蛮大的,所以写一篇博客帮助想学习爬虫的伙伴们. 这里我就以一个简单地爬取淘票票正在热映电影为例,介绍一下一个爬虫的完整流程. 首先,话不多说,上干货——源 ...

  2. 爬虫_电影天堂 热映电影(xpath)

    写了一天才写了不到100行.不过总归是按自己的思路完成了 import requests from lxml import etree import time BASE = 'http://www.d ...

  3. 爬虫_豆瓣电影top250 (正则表达式)

    一样的套路,就是多线程还没弄 import requests import re import json headers = 'Mozilla/5.0 (Windows NT 10.0; WOW64) ...

  4. Python爬虫_豆瓣电视剧

    1 import requests 2 import json 3 import csv 4 5 6 class DoubantvSpider: 7 def __init__(self): 8 # s ...

  5. 用python+selenium抓取豆瓣电影中的正在热映前12部电影并按评分排序

    抓取豆瓣电影(http://movie.douban.com/nowplaying/chengdu/)中的正在热映前12部电影,并按照评分排序,保存至txt文件 #coding=utf-8 from ...

  6. python爬虫实战 获取豆瓣排名前250的电影信息--基于正则表达式

    一.项目目标 爬取豆瓣TOP250电影的评分.评价人数.短评等信息,并在其保存在txt文件中,html解析方式基于正则表达式 二.确定页面内容 爬虫地址:https://movie.douban.co ...

  7. 【收藏】收集的各种Python爬虫、暗网爬虫、豆瓣爬虫、抖音爬虫 Github1万+星

    收集的各种Python爬虫.暗网爬虫.豆瓣爬虫  Github 1万+星 磁力搜索网站2020/01/07更新 https://www.cnblogs.com/cilisousuo/p/1209954 ...

  8. 【布艺DIY】 零基础 做包包 2小时 就OK!_豆瓣

    [布艺DIY] 零基础 做包包 2小时 就OK!_豆瓣 [布艺DIY] 零基础 做包包 2小时 就OK!

  9. 「花田对」CSDN程序员专场——谁来拯救技术宅!_豆瓣

    「花田对」CSDN程序员专场--谁来拯救技术宅!_豆瓣 「花田对」CSDN程序员专场--谁来拯救技术宅!

随机推荐

  1. C. Polycarp Restores Permutation

    链接 [https://codeforces.com/contest/1141/problem/C] 题意 qi=pi+1−pi.给你qi让你恢复pi 每个pi都不一样 分析 就是数学吧 a1 +(a ...

  2. MySql实现分页查询的SQL,mysql实现分页查询的sql语句

    一:分页需求: 客户端通过传递start(页码),limit(每页显示的条数)两个参数去分页查询数据库表中的数据,那我们知道MySql数据库提供了分页的函数limit m,n,但是该函数的用法和我们的 ...

  3. 学习bootstrap3

    官方手册(英文):http://getbootstrap.com/docs/3.3/getting-started/ 中文文档:https://v3.bootcss.com/getting-start ...

  4. MySQL的SQL语句优化-group by语句的优化

    原文:http://bbs.landingbj.com/t-0-243202-1.html 默认情况下,MySQL排序所有GROUP BY col1, col2, ....,查询的方法如同在查询中指定 ...

  5. Vue+iview实现添加删除类

    <style> .tab-warp{ border-bottom: solid 1px #e0e0e0; overflow: hidden; margin-top: 30px; posit ...

  6. [转帖]Oracle 裁员史:技术人死于重组,卒于云计算

    Oracle 裁员史:技术人死于重组,卒于云计算 https://www.infoq.cn/article/tm-mcdHCPCI4eEwr6dbY 大厂裁员 我妈妈也总担心我没工作了 怎么还房贷 田 ...

  7. Eclipse的智能提示的设置

    智能提示修改方式是: Windows——>Preferences——>Java-->Editor-->Content Asist,在Auto activation trigge ...

  8. 关于 html input标签的几个常用操作

    1.清除 input 标签默认样式 input { -moz-appearance: none; outline: 0; text-decoration: none; outline: none; b ...

  9. 关于Vue-cli 组件引入CSS样式文件

    在 Vue-cli 组件 .vue 文件中引入 css 样式表出错   由于使用Vue-cli后, 引入css 样式表 不需要 多余../../ 之类路径  现在写法也发生了改变 <style ...

  10. 结巴(jieba)分词

    一.介绍: jieba: “结巴”中文分词:做最好的 Python 中文分词组件 “Jieba” (Chinese for “to stutter”) Chinese text segmentatio ...