无法提取文本并通过BeautifulSoup查找全部内容 [英] Can't extract the text and find all by BeautifulSoup

查看:612
本文介绍了无法提取文本并通过BeautifulSoup查找全部内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提取所有可用项目,但我只能得到前四项,然后得到'+ plus'。

 从bs4导入urllib2 
导入BeautifulSoup
导入re
导入请求
headers = {'User-Agent':'Mozilla / 5.0(Windows ; U; Windows NT 6.1; en-US; rv:1.9.1.6)Gecko / 20091201 Firefox / 3.5.6'}
url ='https://www.airbnb.fr/rooms/8261637?s= bAMrFL5A'
req = urllib2.Request(url = url,headers = headers)
html = urllib2.urlopen(req)
bsobj = BeautifulSoup(html.read(),'lxml')
b = bsobj.findAll(div,{class:row amenities})



对于b的结果,它不会返回标签内的所有列表。
最后一个是'+ plus',如下所示。

 < span data-reactid =。mjeft4n4sg.0.0.0.0.1.8.1.0.0。$ 1.1.0.0> ; + Plus< / span>< / strong>< / a>< / div>< / div>< / div>< / div>< / div>这是因为在页面加载后使用reactjs填充数据。因此,如果您通过请求下载它,您将看不到数据。



相反,您必须使用 selenium web driver ,打开页面并处理所有的javascript。然后,您可以访问您期望的所有数据

I want to extract the all the available items in the équipements, but I can only get the first four items, and then I got '+ plus'.

import urllib2
from bs4 import BeautifulSoup
import re
import requests
headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}
url = 'https://www.airbnb.fr/rooms/8261637?s=bAMrFL5A'
req = urllib2.Request(url = url, headers = headers)
html = urllib2.urlopen(req)
bsobj = BeautifulSoup(html.read(),'lxml')
b = bsobj.findAll("div",{"class": "row amenities"})

for the result of b, it does not return all the list inside the tag. And for the last one of it is '+ plus', looks like as following.

<span data-reactid=".mjeft4n4sg.0.0.0.0.1.8.1.0.0.$1.1.0.0">+ Plus</span></strong></a></div></div></div></div></div>]

解决方案

This is because data filled up using reactjs after page load. So if you download it via requests you can't see the data.

Instead you have to use selenium web driver, open page and process all the javascripts. Then you can get ccess to all data you expect

这篇关于无法提取文本并通过BeautifulSoup查找全部内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆