朱致慧·爬取信息 #1

Open
p9jfoechi wants to merge 1 commits from 朱致慧·爬取文件 into master
Collaborator
from bs4 import BeautifulSoup
import requests
res = requests.get('https://mp.weixin.qq.com/s/K0u_qPFQtWuH4hk5K2xWfQ')#新闻的网址
res.encoding = res.apparent_encoding

soup = BeautifulSoup(res.text, 'html')#使用html5lib样式来解析网页,看不懂没关系
print(soup)#查看页面源代码
data = soup.select('p')#元素选择器
text=''
for p in data:
    text += p.text.strip()
print(text)
```php from bs4 import BeautifulSoup import requests res = requests.get('https://mp.weixin.qq.com/s/K0u_qPFQtWuH4hk5K2xWfQ')#新闻的网址 res.encoding = res.apparent_encoding soup = BeautifulSoup(res.text, 'html')#使用html5lib样式来解析网页,看不懂没关系 print(soup)#查看页面源代码 data = soup.select('p')#元素选择器 text='' for p in data: text += p.text.strip() print(text) ```
p9jfoechi added 1 commit 4 years ago
p8jt3y9h7 was assigned by p9jfoechi 4 years ago
This pull request has changes conflicting with the target branch.
README.md
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: p8jt3y9h7/python#1
Loading…
There is no content yet.