|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#爬取出版社名称,并写入到txt文档中
import requests
from bs4 import BeautifulSoup
def open_url(url):
#使用代理
proxies = {"http": "127.0.0.1:1080", "https": "127.0.0.1:1080"}
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36"}
res = requests.get(url, headers = headers, proxies = proxies)
return res
def find_data(res):
soup = BeautifulSoup(res.text, 'html.parser')
data = soup.select(".list > a")
return data
def main():
url = "http://www.youlu.net/publisher/"
res = open_url(url)
data = find_data(res)
with open("E:\\2.txt","w",encoding='utf-8') as f:
try:
for i in range(0,len(data)):
f.write(str(data[i].text)+"\n")
except Exception as e:
print("error"+e)
if __name__ == "__main__":
main()
|
|