self.headers['referer'] = self.url_target
# 设置content-type,可以获取数据,默认没有数据
self.headers['content-type']="text/javascript; charset=utf-8"
response = self.s.get(self.url_target + "/lists", proxies=self.proxies, headers=self.headers,
cookies=self.cookies_dict)
# res_dict=json.loads(response.text)
# html=res_dict['page']
# print html
res=etree.HTML(response.text)
lists=res.xpath('//div[@class="GridTimeline-items has-items"]/div')
list_=[]
for l in lists:
item={}
item['name']=l.xpath('./div/div/a[1]/text()')[0].strip()
item['url']="https://twitter.com"+l.xpath('./div/div/a[1]/@href')[0]
item['builder']=l.xpath('./div/div/span/a/text()')[0].strip()
item['members']=l.xpath('./div/div/div/p//text()')[0].strip()
list_.append(item)
print list_
爬虫content-type
猜你喜欢
转载自blog.csdn.net/wu0che28/article/details/82788816
今日推荐
周排行