|
这样应该可以了
- import requests
- from bs4 import BeautifulSoup
- r=requests.get('http://www.cuyoo.com/article-30928-1.html')
- soup=BeautifulSoup(r.text,'lxml')
- en=soup.find(id='en')
- enstring=en.strings
- cn=soup.find(id='cn')
- cnstring=cn.strings
- file=open('/30928.txt','w',encoding='utf-8')
- while True:
- try:
- ensentence=next(enstring)
- #print(ensentence)
- file.write(ensentence)
- file.write('\n')
- cnsentence=next(cnstring)
- #print(cnsentence)
- file.write(cnsentence)
- file.write('\n')
- except StopIteration as e:
- print('Finished')
- break
- file.close()
复制代码 |
|