【问题标题】:Traceback error while running python script运行python脚本时出现回溯错误
【发布时间】:2017-11-13 23:26:46
【问题描述】:

我正在尝试运行此脚本

import requests
from bs4 import BeautifulSoup

url = 'http://www.showmeboone.com/sheriff/JailResidents/JailResidents.asp'
response = requests.get(url)
html = response.content

soup = BeautifulSoup(html)
table = soup.find('tbody', attrs={'class': 'stripe'})
for row in table.findAll('tr'):
print (row.prettify())

我收到此错误:

Traceback (most recent call last)
File: "C:\Users\s\Appdata\Local\Programs\Python\Python36-32\lib\site-
packages\urllib3\connection.py", line 141, in _new_conn

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    我试过你的代码。查看完整的回溯。它说超时错误。您使用的网址没有响应。

    也要改

    soup = BeautifulSoup(html)
    

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

    【讨论】:

    • 如果你使用soup = BeautifulSoup(html, 'html.parser'),并使用任何有效的url,代码就可以正常工作。
    猜你喜欢
    • 2019-08-23
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 2021-03-17
    • 2020-08-02
    • 2022-01-26
    相关资源
    最近更新 更多