Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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 Beauty soup在使用相同URL的两个不同程序中找不到相同的结果_Python_Url_Tkinter_Beautifulsoup - Fatal编程技术网

Python Beauty soup在使用相同URL的两个不同程序中找不到相同的结果

Python Beauty soup在使用相同URL的两个不同程序中找不到相同的结果,python,url,tkinter,beautifulsoup,Python,Url,Tkinter,Beautifulsoup,我创建了一个在控制台中播放的程序。我现在正在把它制作成一个GUI程序。我复制了大部分代码,但为tkinter添加了一些位。我遇到的问题是,我相信URL不会为两个程序显示相同的信息 import requests import re from bs4 import BeautifulSoup def wholeProgram(): word = input("Enter a word: ") webContent = requests.get('https://www.dictionary.c

我创建了一个在控制台中播放的程序。我现在正在把它制作成一个GUI程序。我复制了大部分代码,但为tkinter添加了一些位。我遇到的问题是,我相信URL不会为两个程序显示相同的信息

import requests
import re
from bs4 import BeautifulSoup

def wholeProgram():

word = input("Enter a word: ")
webContent = requests.get('https://www.dictionary.com/browse/'+word)

soup = BeautifulSoup(webContent.text, 'html.parser')

global results
results = soup.find_all('p', attrs={'class':'one-click-content css-it69we e15kc6du7'})

print(results)
在进行故障排除时,我发现上面的代码打印了在“results”变量中找到的内容。这证明它已成功地在页面上找到此特定内容。但当我对其他程序执行相同操作时,它会输出“[]”


在搜索和筛选URL的页面源时(例如“查看源:”)。我发现tkinter程序中没有出现一些内容。我知道这一点,因为在非tkinter程序中,如果您打印“webContent.text”而不是“results”,它将显示页面内容,您可以在内容中找到“一键式内容css-it69we e15kc6du7”。但如果您对tkinter程序执行相同操作,则无法找到“一键式内容css-it69we e15kc6du7”。

您必须在单击按钮后发送请求。还可以使用
get()
获取框中的值

单词“hello”的输出

[<p class="one-click-content css-it69we e15kc6du7">He gets up and goes over to their table and introduces himself, and he says, ‘<span class="italic">Hello</span>, I’m Oliver Reed.</p>, <p class="one-click-content css-it69we e15kc6du7">Forty Years Young: <span class="italic">Hello</span> Kitty and the Power of Cute By Julia Rubin, Racked <span class="italic">Hello</span> Kitty is everywhere.</p>, <p class="one-click-content css-it69we e15kc6du7"><span class="italic">Hello</span> Ladies is, of course, about your British character navigating the L.A. dating scene.</p>, <p class="one-click-content css-it69we e15kc6du7">And where did the idea of the <span class="italic">Hello</span> Ladies movie come about?</p>, <p class="one-click-content css-it69we e15kc6du7">There was one incident that did happen that was dramatized in the <span class="italic">Hello</span> Ladies movie.</p>, <p class="one-click-content css-it69we e15kc6du7">Red he sees my pard passing a saloon, and he says, '<span class="italic">Hello</span>, where did you come from?</p>, <p class="one-click-content css-it69we e15kc6du7">And then, catching sight of Kirkwood's countenance: "Why, <span class="italic">hello</span>, Kirkwood!"</p>, <p class="one-click-content css-it69we e15kc6du7">"<span class="italic">Hello</span> yourself and see how you like it," the mascot of the Ravens called down.</p>, <p class="one-click-content css-it69we e15kc6du7">"<span class="italic">Hello</span>, old man," he cried, shaking Trenton warmly by the hand.</p>, <p class="one-click-content css-it69we e15kc6du7">Why couldn't he ask me how I felt or pull my ear and say "<span class="italic">Hello</span>, Puss?"</p>]
[

他站起来,走到他们的桌子前自我介绍,他说,‘你好,我是奥利弗·里德。

四十岁的年轻人:茱莉亚·鲁宾的《Hello Kitty和可爱的力量》,到处都是备受折磨的Hello Kitty。

=“一键内容css-it69we e15kc6du7”>当然,Hello Ladies是关于你的英国角色在洛杉矶约会场景中的导航。

以及Hello Ladies电影的想法是从何而来的?

有一件事确实发生了,并在《Hello Ladies》电影中被戏剧化了。

红色他看到我的伙伴经过一家酒店,他说,‘你好,你从哪里来?

然后,看到了柯克伍德的脸:“喂,你好,柯克伍德!”

“你好,看看你喜欢它,”乌鸦的吉祥物叫了下来。

“你好,老人,”他喊道,热情地握着特伦顿的手。

为什么他不能问我感觉如何,或者拉我的耳朵说“你好,小猫?”

]
from tkinter import *
import requests
import re
from bs4 import BeautifulSoup
root = Tk()
askWord = Label(root, text="Enter a word")
askWord.pack()
wordEntry = Entry(root)
wordEntry.pack()
wordEntry.focus_set()

def callback():
    global results
    webContent = requests.get('https://www.dictionary.com/browse/'+str(wordEntry.get()))
    soup = BeautifulSoup(webContent.text, 'html.parser')
    results = soup.find_all('p', attrs={'class':'one-click-content css-it69we e15kc6du7'})
    print(results)

button1 = Button(root, text="Get", width=10, command=callback)
button1.pack()
root.mainloop()
[<p class="one-click-content css-it69we e15kc6du7">He gets up and goes over to their table and introduces himself, and he says, ‘<span class="italic">Hello</span>, I’m Oliver Reed.</p>, <p class="one-click-content css-it69we e15kc6du7">Forty Years Young: <span class="italic">Hello</span> Kitty and the Power of Cute By Julia Rubin, Racked <span class="italic">Hello</span> Kitty is everywhere.</p>, <p class="one-click-content css-it69we e15kc6du7"><span class="italic">Hello</span> Ladies is, of course, about your British character navigating the L.A. dating scene.</p>, <p class="one-click-content css-it69we e15kc6du7">And where did the idea of the <span class="italic">Hello</span> Ladies movie come about?</p>, <p class="one-click-content css-it69we e15kc6du7">There was one incident that did happen that was dramatized in the <span class="italic">Hello</span> Ladies movie.</p>, <p class="one-click-content css-it69we e15kc6du7">Red he sees my pard passing a saloon, and he says, '<span class="italic">Hello</span>, where did you come from?</p>, <p class="one-click-content css-it69we e15kc6du7">And then, catching sight of Kirkwood's countenance: "Why, <span class="italic">hello</span>, Kirkwood!"</p>, <p class="one-click-content css-it69we e15kc6du7">"<span class="italic">Hello</span> yourself and see how you like it," the mascot of the Ravens called down.</p>, <p class="one-click-content css-it69we e15kc6du7">"<span class="italic">Hello</span>, old man," he cried, shaking Trenton warmly by the hand.</p>, <p class="one-click-content css-it69we e15kc6du7">Why couldn't he ask me how I felt or pull my ear and say "<span class="italic">Hello</span>, Puss?"</p>]