|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 guili930000 于 2019-1-29 13:51 编辑
看了爬虫的课,但是感觉还是记不太住,所以决定自己试试找个练习一下。但是碰到一个正则表达式的问题。代码如下:
-----------------------------------------------------------------------------------------------------------------------------------------------
import requests
import bs4
import re
url='https://movie.douban.com/top250'
def req_content(url):
content=requests.get(url)
save_file(content)
parser(content)
def save_file(content):
with open('douban.txt','w',encoding='utf-8') as file:
file.write(content.text)
def parser(content):
content=content.text
soap=bs4.BeautifulSoup(content,'html.parser')
target=soap.find_all('span',class_="title")
target2=soap.find_all('span',class_='other')
target=iter(target)
target2=iter(target2)
for i in target:
print (i.text)
final=re.search(r'\w*',i.text).group()
def main():
req_content(url)
if __name__=='__main__':
main()
------------------------------------------------------------------------------------------------------
肖申克的救赎
 / The Shawshank Redemption
霸王别姬
这个杀手不太冷
 / Léon
阿甘正传
 / Forrest Gump
美丽人生
 / La vita è bella
泰坦尼克号
 / Titanic
千与千寻
 / 千と千尋の神隠し
辛德勒的名单
 / Schindler's List
盗梦空间
 / Inception
机器人总动员
 / WALL·E
忠犬八公的故事
 / Hachi: A Dog's Tale
三傻大闹宝莱坞
 / 3 Idiots
海上钢琴师
 / La leggenda del pianista sull'oceano
放牛班的春天
 / Les choristes
大话西游之大圣娶亲
 / 西遊記大結局之仙履奇緣
楚门的世界
 / The Truman Show
龙猫
 / となりのトトロ
星际穿越
 / Interstellar
教父
 / The Godfather
熔炉
 / 도가니
无间道
 / 無間道
当幸福来敲门
 / The Pursuit of Happyness
疯狂动物城
 / Zootopia
触不可及
 / Intouchables
怦然心动
 / Flipped
但是我用过正则表达式\w*以后,结果只剩下了中文的部分,英文的都变不见了,哪位大神教教我啊~其实正则那一块一直弄的不是太清楚
|
|