【问题标题】:How to web scrape from equipment web server如何从设备网络服务器进行网络抓取
【发布时间】:2021-08-20 06:12:00
【问题描述】:

我目前正在尝试从我的称重设备上进行网络抓取。我的称重设备有一个称重传感器和一个控制器。控制器通过以太网连接到我的笔记本电脑。控制器具有内置的网络服务器,因此我可以通过 chrome 浏览器使用指定的 IP 地址 192.168.0.2 访问控制器并切换任何设置并获取重量数据。

我有兴趣使用 python 和提供的 IP 地址从网络服务器上抓取重量数据。我的代码如下:

import requests
import bs4

result = requests.get("http://192.168.0.2")
soup = bs4.BeautifulSoup(result.text,"lxml")
x = soup.select('#DisplayWeight')
print(x)

但是,我收到以下错误:

  1. TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

  2. urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001B2A1EB2820>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

  3. urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.0.2', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001B2A1EB2820>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

  4. requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.0.2', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001B2A1EB2820>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

我不明白出了什么问题,我尝试寻找答案。我可以在这方面寻求帮助吗?谢谢。

最好的问候

【问题讨论】:

    标签: python web-scraping ethernet


    【解决方案1】:

    您尝试提供标题,这是示例。参考:https://stackoverflow.com/a/67798497/3981296

    import requests
    from bs4 import BeautifulSoup
    
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36', "Upgrade-Insecure-Requests": "1","DNT": "1","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language": "en-US,en;q=0.5","Accept-Encoding": "gzip, deflate"}
    html = requests.get("https://www.carmax.com/cars/all",headers=headers)
    soup = BeautifulSoup(html.content, 'html.parser')
    print(soup.prettify())
    

    【讨论】:

      【解决方案2】:

      错误表明没有收到响应。 您需要检查您是否拥有正确的端口号以及 IP 地址。 例如,如果网络服务器在端口 8080 上运行,您将拥有

      result = requests.get("http://192.168.0.2:8080")
      

      【讨论】:

        猜你喜欢
        • 2015-07-21
        • 2017-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-20
        • 1970-01-01
        • 2017-12-30
        • 1970-01-01
        相关资源
        最近更新 更多