Loading

【Day5】3.反爬策略之模拟登录

import urllib.request as ur
import user_agent
import lxml.etree as le

request = ur.Request(
    url='https://edu.csdn.net/mycollege',
    headers={
        'User-Agent':user_agent.get_user_agent_pc(),
        'Cookie':'*******',
    }
)

response = ur.urlopen(request).read().decode('utf-8')
# with open('mycollege2.html','w',encoding='utf-8') as f:
#     f.write(response)

html_x = le.HTML(response)
title_s = html_x.xpath('//li[@class="item_box"]//h1/a/text()')
print(title_s)
posted @ 2019-11-20 15:16  5572  阅读(173)  评论(0编辑  收藏  举报