Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用请求从9gag抓取图像,但图像链接赢了';不显示_Python_Html_Web Scraping_Beautifulsoup_Python Requests - Fatal编程技术网

Python 使用请求从9gag抓取图像,但图像链接赢了';不显示

Python 使用请求从9gag抓取图像,但图像链接赢了';不显示,python,html,web-scraping,beautifulsoup,python-requests,Python,Html,Web Scraping,Beautifulsoup,Python Requests,返回的html不完整,一半的图像链接不可见。看看这个 代码: import requests from bs4 import BeautifulSoup import json import re user_agent = {"User-Agent": "Mozilla/5.0 " "(Windows NT 10.0; Win64; x64) " "AppleWebKit/537.3

返回的html不完整,一半的图像链接不可见。看看这个

代码:

import requests
from bs4 import BeautifulSoup
import json
import re

user_agent = {"User-Agent": "Mozilla/5.0 "
                            "(Windows NT 10.0; Win64; x64) "
                            "AppleWebKit/537.36 (KHTML, like Gecko) "
                            "Chrome/80.0.3987.163 Safari/537.36"}

data = input("Search: ")
n = int(input("Number: "))

url = f'https://9gag.com/search?query={data}'

print(url, "\n")

source = requests.get(url,headers = user_agent).text

soup = BeautifulSoup(source,"lxml")
print(soup.prettify())

for images in soup.findAll("div",class_ = "post-cotainer",limit=n):
    print(images,"\n")
输出未显示包含图像链接的所需“class=post container”:-


请用硬编码变量替换数据和n,这样每个人都可以重现相同的效果。这是否回答了您的问题@不幸的是,没有,但我对此做了一些研究,结果表明请求库只会刮取静态数据,而不是动态数据。因此,我必须用不同的方法使用Selenium@2t2c,那么您能回答您的问题并为我们提供预期的输出吗?因此,我可以检查是否可以使用请求模块请用硬编码变量替换数据和n,这样每个人都可以重现相同的效果这是否回答了您的问题@不幸的是,没有,但我对此做了一些研究,结果表明请求库只会刮取静态数据,而不是动态数据。因此,我必须用不同的方法使用Selenium@2t2c,那么您能回答您的问题并为我们提供预期的输出吗?所以我可以检查是否可以使用请求模块