欢迎来到python!学习。
代码演示:
import re
import requests
from bs4 import BeautifulSoup
def fand_email(url,counts):
data=requests.get(url)
content=data.text
pattern = r'[0-9a-zA-Z._]+@[0-9a-zA-Z._]+\.[0-9a-zA-Z._]+'
p = re.compile(pattern)
m = p.findall(content)
with open('emal.txt','a+') as f:
for i in m:
f.write(i+'\n')
print(i)
counts= counts+1
return counts
def main():
counts=0
numbers=0
for i in range(1,32):
url='http://tieba.baidu.com/p/2314539885?pn=%s'% i
number=fand_email(url,counts)
numbers=numbers+number
print(numbers)
if __name__ == '__main__':
main()
文件 text.py
import requests
from bs4 import BeautifulSoup
def fand_load_image(url):
wb_date = requests.get(url)
#wb_date.encoding = 'gbk'
soup = BeautifulSoup(wb_date.text, 'lxml')
print(soup)
images = soup.select('div.image-item-inner > a')
print(images)
#image=images[0].get('href')
#print(image)
url='https://www.toutiao.com/a6520385683419300359/'
fand_load_image(url)
结果展示