我得到一个我有点理解的错误,但无法用我到目前为止找到的资源解决。我想做的是有一个简单的循环,该循环从列表中获取一个URL,请求其内容,打印输出,然后转到下一个URL。
f = open('urls.txt','r',encoding="utf8") #had to specify encoding because of error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3754: character maps to <undefined>
content_urls = f.readlines()
f.close()
from urllib import request
from bs4 import BeautifulSoup
import time
for each in content_urls:
time.sleep(1)
scraped = request.urlopen(content_urls)
soup = BeautifulSoup(scraped)
print(soup)
前面提到的“列表”似乎是确切的问题: AttributeError:“列表”对象没有属性“超时”
最初的搜索将我带到: AttributeError: 'list' object has no attribute 'timeout' - Trying to process multiple URLs with BeautifulSoup Python list object has no attribute error 'list' object has no attribute 'timeout' and only prints first item in the table AttributeError: 'bytes' object has no attribute 'timeout'
但是,无论如何,我似乎无法实现这些解决方案。 我需要将列表转换成字符串吗?我确实尝试过,但是似乎也没有解决。
非常感谢您的帮助。