python 3网页报废

时间:2017-03-31 04:21:49

标签: python web-scraping

python版本: Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32

我在代码下面运行它工作正常。

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("https://www.flipkart.com/mobiles/pr?otracker=categorytree&page=1&sid=tyy,4io").read()
bsObj = BeautifulSoup(html, "html.parser")
result = bsObj
result.prettify()
nameList = result.findAll("a")
print(nameList)
for name in nameList:
    print(name.get_text())

result.prettify()不是美化HTML代码。我的代码有什么问题吗?

如果我在代码下面运行,我的结果会低于结果。

结果:

[<div class="_2xw3j-" data-reactid="85"><div class="_3taVdZ" data-reactid="86"><div class="_2E-GO0" data-reactid="87"><d
iv class="_CYfoo" data-reactid="88"><div class="row" data-reactid="89"><div class="col-5-12 HdKC4x _2jPfjn" data-reactid
="90"></div></div><div class="row" data-reactid="91"><div class="col-3-12 HdKC4x _2jPfjn" data-reactid="92"></div></div>
</div></div></div></div>]

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("https://www.flipkart.com/mobiles/pr?otracker=categorytree&page=1&sid=tyy,4io").read()
bsObj = BeautifulSoup(html, "html.parser")
result = bsObj
result.prettify()
g_data = result.findAll("div", {"class": "_3wU53n"})
print(g_data)
  

期待如下结果:

Moto E3电源(黑色,16 GB)(2 GB RAM)

我想从网站上获取每个移动信息。请帮帮我。

0 个答案:

没有答案