beautifulsoup

BeautifulSoup partial div class matching

佐手、 提交于 2020-08-05 05:15:12
问题 I need to fetch milestone information from Github by scraping. The milestone information is embedded in 2 types of div classes: table-list-item milestone notdue and table-list-item milestone . How can I retrieve the information contained in both classes? I have: milestones = soup.find_all('div', {'class': 'table-list-item milestone'}) but this line returns empty list for table-list-item milestone notdue Right now I am doing the following (ugly hack): milestones = soup.find_all('div', {'class'

BeautifulSoup partial div class matching

社会主义新天地 提交于 2020-08-05 05:15:01
问题 I need to fetch milestone information from Github by scraping. The milestone information is embedded in 2 types of div classes: table-list-item milestone notdue and table-list-item milestone . How can I retrieve the information contained in both classes? I have: milestones = soup.find_all('div', {'class': 'table-list-item milestone'}) but this line returns empty list for table-list-item milestone notdue Right now I am doing the following (ugly hack): milestones = soup.find_all('div', {'class'

文本分类实战(一)—— word2vec预训练词向量

非 Y 不嫁゛ 提交于 2020-08-04 17:41:32
1 大纲概述   文本分类这个系列将会有十篇左右,包括基于word2vec预训练的文本分类,与及基于最新的预训练模型(ELMo,BERT等)的文本分类。总共有以下系列:    word2vec预训练词向量    textCNN 模型    charCNN 模型    Bi-LSTM 模型    Bi-LSTM + Attention 模型    RCNN 模型    Adversarial LSTM 模型    Transformer 模型    ELMo 预训练模型    BERT 预训练模型    所有代码均在 textClassifier 仓库中。 2 数据集   数据集为IMDB 电影影评,总共有三个数据文件,在/data/rawData目录下,包括unlabeledTrainData.tsv,labeledTrainData.tsv,testData.tsv。在进行文本分类时需要有标签的数据(labeledTrainData),但是在训练word2vec词向量模型(无监督学习)时可以将无标签的数据一起用上。 3 数据预处理   IMDB 电影影评属于英文文本,本序列主要是文本分类的模型介绍,因此数据预处理比较简单,只去除了各种标点符号,HTML标签,小写化等。代码如下: import pandas as pd from bs4 import BeautifulSoup

Day73

人走茶凉 提交于 2020-08-04 14:48:40
对于foreikey  和  manytomany    Model类中写模型,拿到Model对象时,正向查询的时候,模型中点foreikey字段是对象,点manytomany字段是集合   manaytomany(to='Author',throgh='Book2Authors')  这个Booke2Authors表就是中介模型(只针对多对多manytomany)   我们这样写原因1:用我们自己写的第三张表,更易扩展  2.有了manytomany字段,方便我们查询。  3.用了中介模型后,就不能obj.m.add(9)这样操作了,只能使用clear()方法。而是要直接操作第三张表。(因为我们创建的第三张表可能有第三个,第四个字段, 这些个API只能添加固定的manytomany字段。 ) 博客系统(cnblog) 预备知识 1.django的ORM(object relational mapping)  类==》表    类属性==》表字段  类对象==》表记录   跨表查询,分组查询 2.Bootstrap 3.Ajax(它是一种技术,原生可以是JS实现的ajax,我们使用jquery来实现ajax) 4.用户认证   auth 实现功能:   1.基于Ajax和用户认证实现的登录验证      ---验证码   2.基于ajax和form组件实现注册功能     

How can I from bs4 import BeautifulSoup?

▼魔方 西西 提交于 2020-08-02 07:46:16
问题 This code: from bs4 import BeautifulSoup Doesn't work, and gives this error : raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__,attr) ^ SyntaxError: invalid syntax What should i do ? 回答1: You should be using pip to install, so you can simply do pip install beautifulsoup4 That will install the latest BS4, which is 4.3.1 as of 2013-08-15. It supports Python 3. 回答2: Also, if you are using python3, you should use: pip3 install beautifulsoup4 回答3: For Windows...

Beautiful Soup find children for particular div

陌路散爱 提交于 2020-07-31 06:58:45
问题 I have am trying to parse a webpage that looks like this with Python->Beautiful Soup: I am trying to extract the contents of the highlighted td div. Currently I can get all the divs by alltd = soup.findAll('td') for td in alltd: print td But I am trying to narrow the scope of that to search the tds in the class "tablebox" which still will probably return 30+ but is more managable a number than 300+. How can I extract the contents of the highlighted td in picture above? 回答1: It is useful to

Why does error 'NoneType' object has no attribute 'contents' occur with only one of two similar commands?

蹲街弑〆低调 提交于 2020-07-31 04:32:06
问题 I'm extracting content from this url. import requests from bs4 import BeautifulSoup url = 'https://www.collinsdictionary.com/dictionary/french-english/aimer' headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0'} soup = BeautifulSoup(requests.get(url, headers = headers).content, 'html.parser') for script in soup.select('script, .hcdcrt, #ad_contentslot_1, #ad_contentslot_2'): script.extract() entry_name = soup.h2.text content1 = ''.join(map

Python一键获取日漫Top100榜单电影信息

╄→гoц情女王★ 提交于 2020-07-29 11:13:50
最近看到一个 UP 主做的视频,使用可视化动态图,把目前播放量最多的 UP 主一一列出来,结果第一名是哔哩哔哩番剧,第一名的播放量是第二名近 10 倍。 B站的番剧数量,也是相对其他平台比较多的,而且质量都还不错。说实话,刚开始用哔哩哔哩的时候,就是为了看番剧。作为一个喜欢看番剧的 pk 哥,我决定用爬虫爬取一下日本动漫电影 TOP100 都有哪些?网上看了一下,时光网正好有这个排行榜,而且信息相对来说比较全。 所以我决定用爬虫把这个榜单上 Top100 的所有电影信息全部保存为 csv 文件放在本地,看有没有之前我遗漏的经典动漫电影。 以下是保存的效果。保存的列包括电影名称、导演编剧、发行公司、更多片名、评分、首日票房、总票房。有些电影没有评分和票房信息的就直接显示为空。 获取电影ID信息 本次爬虫项目主要分为三个部分。第一部分我们要获取电影的 Id信息,因为我们需要保存的所有信息,都和这个有关。Id从哪里获取呢?我们打开这个榜单页面的源代码。源代码中我们可以看到,id都在链接后面。 为了缩小范围,我们发现这些链接都在 class=top_nlist 里面,我们用 beautifulsoup 库提取属性 class= top_nlist 所有的元素。然后用正则表达式,提取出每页的 id信息。 这里第 1 个页面需要特殊处理一下,因为第 2 个页面到第 10

Python爬虫:用Scrapy框架爬取漫画(附源码)

你说的曾经没有我的故事 提交于 2020-07-29 07:16:07
scrapy 是一个为了爬取网站数据,提取结构性数据而编写的应用框架。关于框架使用的更多详情可浏览官方文档,本篇文章展示的是爬取漫画图片的大体实现过程。 Scrapy环境配置 首先是 scrapy 的安装,博主用的是Mac系统,直接运行命令行: pip install Scrapy 对于html节点信息的提取使用了 Beautiful Soup 库,大概的用法可见之前的一篇文章,直接通过命令安装: pip install beautifulsoup4 对于目标网页的 Beautiful Soup 对象初始化需要用到 html5lib 解释器,安装的命令: pip install html5lib 安装完成后,直接在命令行运行命令: scrapy 可以看到如下输出结果,这时候证明scrapy安装完成了。 Scrapy 1.2.1 - no active project ​ Usage: scrapy <command> [options] [args] ​ Available commands: bench Run quick benchmark test commands fetch Fetch a URL using the Scrapy downloader genspider Generate new spider using pre-defined templates

Python基于BeautifulSoup爬取京东商品信息

做~自己de王妃 提交于 2020-07-29 07:01:52
今天小编利用美丽的汤来为大家演示一下如何实现京东商品信息的精准匹配~~ HTML 文件其实就是由一组尖括号构成的标签组织起来的,每一对尖括号形式一个标签,标签之间存在上下关系,形成标签树;因此可以说Beautiful Soup库是解析、遍历、维护“标签树”的功能库。 如何利用BeautifulSoup抓取京东网商品信息 首先进入京东网,输入自己想要查询的商品,向服务器发送网页请求。在这里小编仍以关键词“狗粮”作为搜索对象,之后得到后面这一串网址: https://search.jd.com/Search?keyword=%E7%8B%97%E7%B2%AE&enc=utf-8,其中参数的意思就是我们输入的keyword,在本例中该参数代表“狗粮”,具体详情可以参考Python大神用正则表达式教你搞定京东商品信息。所以,只要输入keyword这个参数之后,将其进行编码,就可以获取到目标URL。之后请求网页,得到响应,尔后利用bs4选择器进行下一步的数据采集。 商品信息在京东官网上的部分网页源码如下图所示: 狗粮信息在京东官网上的网页源码 仔细观察源码,可以发现我们所需的目标信息是存在<li data-sku="*****" class="gl-item">标签下的,那么接下来我们就像剥洋葱一样,一层一层的去获取我们想要的信息。 直接上代码,如下图所示: 请求网页,获取源码