栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python爬虫记录

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python爬虫记录

import requests
from lxml import html
header = {
        "Connection": "close",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"}
etree = html.etree
response = requests.get("http://cansang.gxnongmu.com/docList.aspx?catId=183&Page=1",headers = header)
result = response.content.decode('utf8')
html_result = etree.HTML(result)
Sericulture_titles = html_result.xpath("//div[@class='zt2listnr']/ul[1]/li")
for Sericulture_title in Sericulture_titles:
        Sericulture_title_name = Sericulture_title.xpath("./a/text()")
        Sericulture_title_href = Sericulture_title.xpath("./a/@href")
        print(Sericulture_title_name)
        print(Sericulture_title_href)

在这个过程中遇到两个问题:
问题一:
requests.exceptions.ProxyError: HTTPConnectionPool(host=‘127.0.0.1’, port=8888): Max retries exceeded with url:
网上查了一下是代理的问题。
解决:将代理关闭

问题二:
requests.exceptions.ConnectionError: (‘Connection aborted.’, RemoteDisconnected('Remote end…
原因:request的连接数过多而导致Max retries exceeded
在header中不使用持久连接,在headers中加入以下代码:

'Connection': 'close'
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/283727.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号