Xpath Python 网络抓取
Xpath Python web scraping
这是我的代码。我正在尝试打印公司名称并且它有效
但是在打印公司地址时总是有空值。
from lxml import html
import requests
from bs4 import BeautifulSoup
page = requests.get('https://appext20.dos.ny.gov/lcns_public/bus_name_inq_frm?p_record_id=160001624')
tree = html.fromstring(page.content)
Business_Name=tree.xpath("/html/body/center[2]/table/tr[11]/td/text()")
print(Business_Name)
Business_address=tree.xpath("/html/body/center[2]/table/tr[16]/td/text()")
print(Business_address)
试试这个
driver.get('https://appext20.dos.ny.gov/lcns_public/bus_name_inq_frm?p_record_id=160001624')
table_element = driver.find_elements_by_css_selector('table[summary="for layout only"]>tbody')
business_address = table_element[0].find_element_by_css_selector('tr:nth-last-child(11)>td')
打印(business_address.text)
你的代码不工作的原因是因为没有继续到tr,所以对于业务地址,从底部阅读
这是我的代码。我正在尝试打印公司名称并且它有效 但是在打印公司地址时总是有空值。
from lxml import html
import requests
from bs4 import BeautifulSoup
page = requests.get('https://appext20.dos.ny.gov/lcns_public/bus_name_inq_frm?p_record_id=160001624')
tree = html.fromstring(page.content)
Business_Name=tree.xpath("/html/body/center[2]/table/tr[11]/td/text()")
print(Business_Name)
Business_address=tree.xpath("/html/body/center[2]/table/tr[16]/td/text()")
print(Business_address)
试试这个
driver.get('https://appext20.dos.ny.gov/lcns_public/bus_name_inq_frm?p_record_id=160001624')
table_element = driver.find_elements_by_css_selector('table[summary="for layout only"]>tbody')
business_address = table_element[0].find_element_by_css_selector('tr:nth-last-child(11)>td')
打印(business_address.text)
你的代码不工作的原因是因为没有继续到tr,所以对于业务地址,从底部阅读