【问题标题】:How to get Html code after crawling with pythonpython爬取后如何获取Html代码
【发布时间】:2017-07-15 23:26:06
【问题描述】:

https://plus.google.com/s/casasgrandes27%40gmail.com/top

我需要使用 python 抓取以下页面,但我需要它的 HTML 而不是链接的通用源代码。

例如

打开链接:plus.google.com/s/casasgrandes27%40gmail.com/top 没有登录倒数第二个缩略图将是“G Suite”。

<div class="Wbuh5e" jsname="r4nke">G Suite</div>

执行此 python 代码后,我无法找到上面的 HTML 代码行。

from bs4 import BeautifulSoup
import requests

L = list()
r  = requests.get("https://plus.google.com/s/casasgrandes27%40gmail.com/top")
data = r.text
soup = BeautifulSoup(data,"lxml")

print(soup)

【问题讨论】:

  • 我是用BeautifulSoup爬取页面的,见上面的代码

标签: python html web-crawler rendering


【解决方案1】:

要获取汤对象,请尝试以下操作

page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')

http://docs.python-requests.org/en/master/user/quickstart/#binary-response-content https://www.crummy.com/software/BeautifulSoup/bs4/doc/

【讨论】:

  • Not working page content is not there, open the link: plus.google.com/s/casasgrandes27%40gmail.com/top without login second last thumbnail will be G Suite (
    G Suite
    )。执行此代码后我无法找到。
【解决方案2】:

您可以尝试使用此代码来读取 HTML 页面:

import urllib.request

urls = "https://plus.google.com/s/casasgrandes27%40gmail.com/top"
html_file = urllib.request.urlopen(urls)
html_text = html_file.read()
html_text = str(html_text)
print(html_text)

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-03-24
  • 2019-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-06
  • 2017-03-05
  • 1970-01-01
相关资源
最近更新 更多