【发布时间】:2019-05-04 11:30:57
【问题描述】:
我正在用 python 编写一个程序,它会扫描我朋友和我自己的 GitHub 页面并显示所有上传文件的名称。我已经设法让它做到这一点。所有文件的名称都在标签下。问题是标签下还有其他随机文本,例如“通过上传添加文件”。我不希望这些出现。任何帮助,将不胜感激。亲切的问候。埃里克
我在打印最终结果时尝试了字符串剥离,但这仍然行不通。
这是我的代码:
import bs4
import requests
from bs4 import BeautifulSoup as soup
import lxml
import re
import time
import os
import webbrowser
import re
def webscrape():
res = requests.get('https://github.com/Dukesan7/jerichson')
type(res)
soup = bs4.BeautifulSoup(res.text, 'lxml')
type(soup)
file = soup.select('a')
file[1].getText()
time.sleep(1)
files = str(file)
clean = re.compile('<.*?>')
files = re.sub(clean, '', files)
print (files)
time.sleep(1)
print ("1. Main Menu: 1")
print ("2. exit?: 2")
op = input (":")
if op == "2":
exit()
else:
MainMenu()
【问题讨论】:
-
您想包括还是排除文件夹?例如谷歌2
标签: python python-3.x web-scraping beautifulsoup