Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium没有给出预期的结果_Python_Selenium_Beautifulsoup_Screen Scraping - Fatal编程技术网

Python Selenium没有给出预期的结果

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

我想浏览一下Github趋势页面,并得出以下代码。由于某种原因,它无法正常工作,而是发出了一些其他会话代码。知道为什么吗? 这是我的密码-

#!/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']))