#encoding=utf-8 import requests from lxml import etree from multiprocessing.dummy import Pool cook={"Cookie":"xxxxxx"} # cook = {"Cookie":""} # url = 'https://weibo.cn/u/1890493665' url = 'xxx' html = requests.get(url,cookies = cook).content ##################################### # # 两种方法二选一 # # content返回的是一个byte型的数据 # # text返回的是一个Unicode字符串,不支持显示 # html = requests.get(url,cookies = cook).text # html = bytes(bytearray(html,encoding='utf-8')) print html selector = etree.HTML(html) # print selector content = selector.xpath('//span[@class="ctt"]') # content = selector.xpath('//head/title/text()') # print content for each in content: text = each.xpath('string(.)') b = 1 print text
cookies模拟登陆新浪微博
最新推荐文章于 2019-08-29 22:14:48 发布