forked from dataabc/weiboSpider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue dataabc#374
- Loading branch information
Showing
3 changed files
with
14 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name='weibo-spider', | ||
version='0.2.7', | ||
version='0.2.8', | ||
author='Chen Lei', | ||
author_email='[email protected]', | ||
description='新浪微博爬虫,用python爬取新浪微博数据。', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
from .util import handle_html | ||
from .parser import Parser | ||
from .util import handle_html | ||
|
||
|
||
class PhotoParser(Parser): | ||
def __init__(self, cookie, user_id): | ||
self.cookie = cookie | ||
self.url = "https://weibo.cn/" + str(user_id) + "/photo?tf=6_008" | ||
self.selector = handle_html(self.cookie, self.url) | ||
self.user_id = user_id | ||
|
||
def extract_avatar_album_url(self): | ||
# Finds the href attribute of the table td div element with text 头像相册, e.g. | ||
# <a href="/album/166564740000001980768563?rl=1"><img width="80" height="80" src="https://tvax1.sinaimg.cn/crop.0.0.1080.1080.180/76102133ly8ga961tpte6j20u00u0q65.jpg?KID=imgbed,tva&Expires=1629227741&ssig=TEUDkMXcS1" alt="头像相册"></a> | ||
result = self.selector.xpath('//img[@alt="头像相册"]/../@href') | ||
return "https://weibo.cn" + result[0] | ||
if len(result) > 0: | ||
return "https://weibo.cn" + result[0] | ||
else: | ||
return "https://weibo.cn/" + str(self.user_id) + "/avatar?rl=0" |