Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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
TypeError:类型为'的对象;HTTPConnection';在Python 3.7中没有len()_Python_Python 3.x_Python Requests_Streamlit - Fatal编程技术网

TypeError:类型为'的对象;HTTPConnection';在Python 3.7中没有len()

TypeError:类型为'的对象;HTTPConnection';在Python 3.7中没有len(),python,python-3.x,python-requests,streamlit,Python,Python 3.x,Python Requests,Streamlit,我正在尝试用Streamlight框架制作一个web抓取应用程序,但是在编写下面的代码时出现了下面的错误,有人能建议如何解决这个问题吗 url = st.text_input('www.example_abc.com') # type of this is .txt connected = http.client.HTTPConnection(url) # converting type to http.client.HTTPResponse TypeError: object of type

我正在尝试用Streamlight框架制作一个web抓取应用程序,但是在编写下面的代码时出现了下面的错误,有人能建议如何解决这个问题吗

url = st.text_input('www.example_abc.com') # type of this is .txt
connected = http.client.HTTPConnection(url) # converting type to http.client.HTTPResponse

TypeError: object of type 'HTTPConnection' has no len()
 page_soup = bs.BeautifulSoup(source, 'html.parser')
File "c:\programdata\anaconda3\lib\site-packages\bs4\__init__.py", line 245, in __init__
    elif len(markup) <= 256 and (
我要求类型为“http.client.HTTPResponse”

我写的代码:

import bs4 as bs
import streamlit as st

source_txt = st.text_input("") #Input url will be entered, say: https://rgtnt.com/
st.write(source_txt)

import http
source = http.client.HTTPConnection(source_txt)

page_soup = bs.BeautifulSoup(source, 'html.parser')

您能否提供必要的代码来重现您的错误,即库导入和示例url?您好,谢谢您的回复。我已经用代码更新了这篇文章。你为什么不使用更简单的请求包从HTTP源获取数据?我使用streamlit,所以我得到的url类型是文本,如何将文本转换为HTTP请求?
import bs4 as bs
import streamlit as st

source_txt = st.text_input("") #Input url will be entered, say: https://rgtnt.com/
st.write(source_txt)

import http
source = http.client.HTTPConnection(source_txt)

page_soup = bs.BeautifulSoup(source, 'html.parser')