Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
part1
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
reeves
part1
Commits
cc23db60
Commit
cc23db60
authored
Jun 15, 2021
by
reeves
🛀🏻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注释
parent
059c3a22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
2 deletions
+4
-2
sample_sina_new.py
py/sample_sina_new.py
+4
-2
No files found.
py/sample_sina_new.py
View file @
cc23db60
...
...
@@ -22,7 +22,8 @@ def save_to_db(url, html):
}
last_id
=
db
.
table_insert
(
'sinatilte'
,
item
)
# 输入为 respond
# 利用了xpath 分析 //a 获取根节点中所有的a标签,最后组装为字典数组
def
analysisA
(
htmlText
):
linklist
=
htmlText
.
xpath
(
"//a"
)
news_linkDics
=
[]
...
...
@@ -42,7 +43,8 @@ def crawl():
}
htmlText
=
requests
.
get
(
sina_url
,
headers
=
_headers
)
.
text
.
encode
(
'iso-8859-1'
)
.
decode
(
'utf-8'
)
# 提取response 中的a标签 的href 和 文本,
# 得到的结果为 [{"url":“text"}]
DicArray
=
analysisA
(
etree
.
HTML
(
htmlText
))
news_links
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment