简单python爬虫

Java_Coder 发布于 2015/06/15 21:49
阅读 421
收藏 0

刚刚接触python,想学习一下爬虫。假设:

data_soup.find_all(attrs={"data-foo": "value"}) 

# [<div data-foo="value">one</div>,<div data-foo="value">two</div>]

然后我要怎么活取每个div里面的数据呢?   

for x in data:  。。。。。。。


 

加载中
0
Java_Coder
Java_Coder

已解决:


import requests from bs4 import BeautifulSoup

response = requests.get("http://www.cs.swust.edu.cn/index.php?mact=News,m0d722,default,1&m0d722number=25&m0d722category=%E6%96%B0%E9%97%BB%E5%8A%A8%E6%80%81&m0d722summarytemplate=newsPageList&m0d722pagenumber=2&m0d722returnid=36&m0d722returnid=36&page=36")
soup = BeautifulSoup(response.text)
for x in soup.findAll('div',{'class':"newsSummarytitle"})
 soup_str = BeautifulSoup(str(x))
print(soup_str) print(soup_str.find('a').text)

返回顶部
顶部