Python Selenium没有给出预期的结果
我想浏览一下Github趋势页面,并得出以下代码。由于某种原因,它无法正常工作,而是发出了一些其他会话代码。知道为什么吗? 这是我的密码-Python Selenium没有给出预期的结果,python,selenium,beautifulsoup,screen-scraping,Python,Selenium,Beautifulsoup,Screen Scraping,我想浏览一下Github趋势页面,并得出以下代码。由于某种原因,它无法正常工作,而是发出了一些其他会话代码。知道为什么吗? 这是我的密码- #!/usr/bin/python3 from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Firefox() driver.get('https://github.com/trending') content_element = driver.f
#!/usr/bin/python3
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Firefox()
driver.get('https://github.com/trending')
content_element = driver.find_elements_by_xpath("/html/body/div[4]/main/div[3]/div/div[2]/article[1]/h1/a")
for element in content_element:
print(element)
driver.close()
谢谢您可以使用
beautifulsoup
使用以下示例提取所有趋势存储库:
import requests
from bs4 import BeautifulSoup
url = 'https://github.com/trending'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
for a in soup.select('article h1 a'):
print('{:<50} {}'.format(a.get_text(strip=True, separator=' '), 'https://github.com' + a['href']))
您可以使用以下示例使用
beautifulsoup
提取所有趋势存储库:
import requests
from bs4 import BeautifulSoup
url = 'https://github.com/trending'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
for a in soup.select('article h1 a'):
print('{:<50} {}'.format(a.get_text(strip=True, separator=' '), 'https://github.com' + a['href']))