![](/img/trans.png)
[英]How can i solve problem with installing lightgbm gpu on windows 10?
[英]How to solve module problem in Windows 10?
我有一個代碼如下。
我使用python 3.7
idle 運行此代碼,該代碼運行成功。 但是當我將它保存為file.py
並使用 cmd 運行它時,它會彈出import module
錯誤。
我的代碼:
import requests
from lxml import html
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3'}
# url to scrape data from
link = 'https://www.bhaskar.com/sports/'
# path to particular element
path = '//*[@id="top-nav1"]'
response = requests.get(link,headers)
byte_string = response.content
# get filtered source code
source_code = html.fromstring(byte_string)
print(source_code)
# jump to preferred html element
tree = source_code.xpath(path)
print(tree.text_content())
錯誤:無法從“lxml”導入名稱“html”
您通過將腳本命名為lxml.py
來混淆 Python 的導入機制,該腳本與您正在導入的lxml
package 同名。
將其重命名為lxml_test_thing.py
即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.