0

GitHub API를 전혀 사용하지 않고 https://github.com/themichaelusa/Trinitum/find/master과 같은 링크에서 모든 파일 경로를 긁어 내려고합니다.GitHub Repo에서 파일 경로를 긁어 내면 응답이 400이지만 브라우저에서보기가 제대로 작동합니다.

위의 링크는 이와 같은 URL을 만드는 데 사용되는 HTML (table, id = 'tree-finder-results', class = '트리 브라우저 css-truncate')의 data-url 속성을 포함합니다 이 사전을 표시 https://github.com/themichaelusa/Trinitum/tree-list/45a2ca7145369bee6c31a54c30fca8d3f0aae6cd

: 당신은 크롬과 같은 브라우저에서 볼

{"paths":["Examples/advanced_example.py","Examples/basic_example.py","LICENSE","README.md","Trinitum/AsyncManager.py","Trinitum/Constants.py","Trinitum/DatabaseManager.py","Trinitum/Diagnostics.py","Trinitum/Order.py","Trinitum/Pipeline.py","Trinitum/Position.py","Trinitum/RSU.py","Trinitum/Strategy.py","Trinitum/TradingInstance.py","Trinitum/Trinitum.py","Trinitum/Utilities.py","Trinitum/__init__.py","setup.cfg","setup.py"]} 

. 그러나 GET 요청은 <[400] Response>을 산출합니다. 그것으로 무엇이 잘못되었는지

username, repo = ‘themichaelusa’, ‘Trinitum’ 
ghURL = 'https://github.com' 
url = ghURL + ('/{}/{}/find/master'.format(self.username, repo)) 
html = requests.get(url) 
soup = BeautifulSoup(html.text, "lxml") 
repoContent = soup.find('div', class_='tree-finder clearfix') 
fileLinksURL = ghURL + str(repoContent.find('table').attrs['data-url']) 
filePaths = requests.get(fileLinksURL) 
print(filePaths) 

확실하지 : 여기

은 내가 사용하는 코드입니다. 제 이론은 첫 번째 링크가 두 번째 링크가 우리가 목표로하는 repo의 파일 경로를 보여줄 수있는 쿠키를 생성한다는 것입니다. 코드를 통해이를 달성하는 방법을 확신 할 수 없습니다. 정말 몇 가지 포인터를 주셔서 감사합니다!

+0

당신이'주의 예 못했다는/advanced_example.py'는'HTTPS를 기준으로하지 않습니다 : // github.com/themichaelusa/Trinitum/blob/master'? –

+0

제 조언은 브라우저의 개발 도구를 사용하여 실제로 어떤 요청이 전송되는지 신중하게 통제하고,'url'과'fileLinksURL'을 출력하고 비교하는 것입니다. –

답변

0

덤프 .py 파일을 포함하는 링크는 동적으로 생성되므로이를 잡으려면 셀렌을 사용해야합니다. 나는 이것이 당신이 기대 한 것이라고 생각합니다.

from selenium import webdriver ; from bs4 import BeautifulSoup 
from urllib.parse import urljoin 

url = 'https://github.com/themichaelusa/Trinitum/find/master' 
driver=webdriver.Chrome() 
driver.get(url) 
soup = BeautifulSoup(driver.page_source, "lxml") 
driver.quit() 
for link in soup.select('#tree-finder-results .js-tree-finder-path'): 
    print(urljoin(url,link['href'])) 

부분 결과 : // github.com/themichaelusa/Trinitum/발견/master`하지만`은 https :

https://github.com/themichaelusa/Trinitum/blob/master 
https://github.com/themichaelusa/Trinitum/blob/master/Examples/advanced_example.py 
https://github.com/themichaelusa/Trinitum/blob/master/Examples/basic_example.py 
https://github.com/themichaelusa/Trinitum/blob/master/LICENSE 
https://github.com/themichaelusa/Trinitum/blob/master/README.md 
https://github.com/themichaelusa/Trinitum/blob/master/Trinitum/AsyncManager.py 
+0

@Michael Usachenko, 코드를 사용해 보셨습니까? – SIM