【问题标题】:Html has java Script in it. How to extract HTML tags from itHtml 中包含 java 脚本。如何从中提取 HTML 标签
【发布时间】:2019-07-07 11:58:37
【问题描述】:

我必须下载 URL 链接的所有 html。但我没有收到任何 HTML 标签。相反,我只得到了这些行。

<!doctype html>
<html lang="en">
<head><meta charset="utf-8">  
<meta name="viewport" content="width=device-width, initial-scale=1">    <title></title>
 <link href="/github-user-search/app.bundle.562f293b75a96de878ab.css" rel="stylesheet"></head><body>
 <div id="root"></div>
 <script type="text/javascript" src="/github-user-search/app.bundle.562f293b75a96de878ab.js"></script></body>
 </html>

import requests
import urllib.request
import time
from bs4 import BeautifulSoup


url ='https://simonsmith.github.io/github-user-search/#/search?per_page=42&page=1&q=Ben%20Newman'
response = requests.get(url)
print(response.content)
soup = BeautifulSoup(response.text, 'html.parser')
soup.findAll('a')

【问题讨论】:

  • 你从那个页面到底想要什么?真的只是所有的html吗?

标签: html python-3.x web-scraping beautifulsoup python-requests


【解决方案1】:

当你向上面的url发出请求时,内容是通过javascript异步加载的,所以当你使用内容时,你将无法scrape异步加载的内容 在解析之前需要等待内容加载, 我建议使用 phantom js / puppeteer 等待动态内容加载然后抓取,使用如下所示的 jquery 等到内容加载,等到页面上加载用户详细信息,然后继续数据提取

$('*[class^="User_"]')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-28
    • 2023-03-19
    • 2021-05-05
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    相关资源
    最近更新 更多